When trying to export a data tier application or dacpac from a database that contains functions that use "for xml" every single function and every single object that depends upon that function fails and I am not able to create the dacpac. The wizard reports those objects as not supported.
Database : SQL Server 2008 R2
The error that the functions fail with:
[dbo].[fn_FunctionName] () Failed Depends on object '[XmlData].[value] (UnresolvedEntity)', which does not exist in this database.
Example query:
declare #XMLColumn xml = '<Example><Node>Test</Node></Example>'
select XmlData.value('.', 'varchar(50)') + ';'
from #XMLColumn.nodes('/Example/Node') T2(XmlData)
for xml path('')
I know it has been a long time but changing your query to the following
declare #XMLColumn xml = '<Example><Node>Test</Node></Example>'
select T2.XmlData.value('.', 'varchar(50)') + ';'
from #XMLColumn.nodes('/Example/Node') T2(XmlData)
for xml path('')
Related
I am receiving data files in XML format from a public agency. The structure of the files and the notations within make me think that what I am seeing is a bulk table dump from SQL Server. Each XML file starts with a schema definition. This is followed by multiple elements, each element looking like it contains one table row of data. The structure of the files makes me think that they were created by some facility within SQL Server itself.
I have looked at the SQL Server docs and online articles, but I cannot find information on how this would be accomplished. I am thinking that if there is a built in facility to export the data in this format, there must be a built in facility to import the data back into SQL Server.
A snippet of one XML file showing the opening schema section and a couple of data elements can be found here;
sample data XML file
Am I correct in thinking that these files are SQL Server dumps? If so, who are these exported and then imported?
You can use xml functionality of SQL Server. Something like this.
Import
declare #x xml = N'--your xml here'
; with xmlnamespaces('urn:schemas-microsoft-com:sql:SqlRowSet1' as p)--required as xml has xmlns attribute
--insert mytable
select t.v.value('p:pool_idn[1]','int') pool_idn, --note p: prefix
t.v.value('p:eff_dte[1]','datetime') eff_dte,
t.v.value('p:pool_nam[1]','varchar(50)') pool_nam
--and so on
from #x.nodes('root/p:pool') t(v)
Export
select * from mytable
for xml auto, elements, root, xmlschema('urn:my:schema')
I have a query in MS SQL:
select convert(xml,replace((select * from Name for xml path('')),' ', ''))
and need to convert this query in TeraData syntax.
I read that there is a procedure XMLPUBLISH in Teradata which transforms my query in XML format (like for xml path('') in MS SQL).
But I have been unable to find an example of using this procedure.
Please, help convert the request into Teradata syntax (with this function or other).
I want to generate an XML in UTF-8 encoding. But by default it is generating in UCS-2.
Please help me to generate XML in UTF-8 encoding. Below is my query:
select
isnull(cast('5678' as nvarchar(50)),'') [Vlootnummer],
isnull((select top 1 cast(EngineNo as nvarchar(50))
from VTS_DEMO.dbo.VehicleDetails v
join VTS_DEMO.dbo.VehicleDevice vd on v.VehicleId = vd.VehicleId
and ObuID = '353234023894171'), '') as Kenteken,
isnull((select top 1 cast(FillingStationName as nvarchar(50)) Units
from VTS_DEMO.dbo.FillingStation
where GeoFenceId = 3655),'') Locatie,
isnull((select top 1 GeofenceCode
from VTS_DEMO.dbo.GeoFence
where GeoFenceId = 3655), '') GeoFencingID,
isnull(cast(case when 1 = 0 then '' else '2017-02-07T23:15:25Z' end as nvarchar(50)),'') Aankomsttijd,
isnull(cast(case when 1 = 0 then '2017-02-07T23:15:25Z' else NULL end as nvarchar(50)),'') Vertrektijd
FOR XML PATH('Notificatie')
When I send this XML as attachment in mail using stored procedure msdb.dbo.sp_send_dbmail, when its opened in notepad++ then it shows UCS-2.
As per the MSDN documentation, It is a limitation on the XML datatype on MS SQL Server. SQL Server always saves an XML datatype with the character encoding of UCS-2.
The XML declaration PI, for example, , is not preserved when storing XML data in an xml data type instance. This is by design. The XML declaration () and its attributes (version/encoding/stand-alone) are lost after data is converted to type xml. The XML declaration is treated as a directive to the XML parser. The XML data is stored internally as ucs-2. All other PIs in the XML instance are preserved.
Considering the above, you can add this manually to take affect.
In an attempt to do this, you can use the following to gain advantage of FOR XML
SELECT CAST((SELECT [Columns] FROM [Tables] FOR XML AUTO) AS VARCHAR(MAX)) AS xmldata
You can check this answer for a discussion similar to this.
Hope this helps!
I'm trying to load incremental data from ODBC server to SQL server using common table expression.
When running the query in the Dbeabver application, is executed correctly:
with test as
(
SELECT userid,sum(goldbalance)
FROM Server.events_live
where eventTimestamp>=DATE '2016-01-01' + INTERVAL '-100 day'
group by userid
order by sum(goldbalance) desc)
)
select * from test
when running it from an sql command expression of the ODBC source, it fails due to wrong syntax. It looks as follow:
with test as
(
SELECT userid,sum(goldbalance)
FROM deltadna.events_live
where eventTimestamp>=DATE '"+#[User::datestring]+"' + INTERVAL '-100 day'
group by userid
order by sum(goldbalance) desc)
)
select * from test"
the datestring variable is getting the server date and convert it to string in the format yyyy-mm-dd. I'm usually use this method to pull data from ADO.NET and it works properly.
Is there any other way to pull incremental data from ODBC server using ssis variables?
With OLE DB
Try this code, it works for me with my own tables with SQL Server :
SELECT userid,sum(goldbalance) AS SUMGOLD
FROM deltadna.events_live
WHERE eventTimestamp >= DATEADD(DAY, -100,CONVERT(DATE,?))
GROUP BY userid
ORDER BY SUMGOLD desc
You have to click on Parameters in the OLEDB Source Editor to configure what you need. Use the '?' to represent a variable in your query.
If you query if too complicated, stored it in a stored procedure and call it like this:
EXEC shema.storedProcedureName ?
And map the '?' to your variable #user::DateString
With ODBC
The expressions are outside the data flow in Data Flow Properties.
Select the expression property and add your dynamic query.
And your expression will be
"SELECT userid,sum(goldbalance) AS SumGold
FROM deltadna.events_live
where eventTimestamp>=DATE "+#[User::datestring]+" +INTERVAL '-100 day'
group by userid
order by SumGold desc"
I would like to write a stored procedure as below in SQL Server.
CREATE PROC [dbo].[Employee_delete]
AS
BEGIN
SELECT *
FROM #employee
FOR XML PATH(''), root ('EmployeeDelete'),xmlschema
END
But I'm getting the error--> 'inline schema is not supported with for xml path xmlschema'. May I know, how can I achieve XMLSchema with code "FOR XML PATH(''), root ('EmployeeDelete'),xmlschema"
To auto generate schemas in biztalk , I have to use word "xmlSchema"
Thanks in advance
If you are using BizTalk-2010 you should be using the WCF-SQL adapter for which you don't need to select as FOR XML to be able to generate schemas.
Try...
FOR XML AUTO,ROOT('EmployeeDelete'), TYPE, ELEMENTS XSINIL, XMLSCHEMA