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).
Related
i'm working on mssql server 2017.
i got table with 'name' nvarchar column with values that look like '\u039b \u041e \u0422 \u0422 \u0410'
(sequence of '\u0[number][number][number or letter]')
how do i convert them to the correct characters?
This is actually the same as JSON escaping.
You can use JSON_VALUE to get the value out, by creating a JSON array
SELECT JSON_VALUE('["' + t.name + '"]', '$[0]')
FROM YourTable t;
db<>fiddle
I am converting Access query to SQL Server.
I want to convert below lines to SQL
1. Format (210.6, "Standard")
2. Format (210.6, "#,##0.00")
How do i convert it to SQL query.
I have tried with below, but still not able to find the solution.
For the first query, i found below solution, which is correct
1. CONVERT(varchar, CAST(tSRO.OutputF11 AS money), 1)
Now, for second query, i do not know what i have to do.
From SQL Server 2012+ you can use FORMAT:
SELECT FORMAT(210.6, '#,##0.00') -- 210.60
SELECT FORMAT(1210.6, '#,##0.00') -- 1,210.60
LiveDemo
SQL Server before 2012:
SELECT REPLACE(CONVERT(VARCHAR,CONVERT(MONEY, 1210.6),1),'.00','') -- 1,210.60
LiveDemo2
Warning:
This operation is pure for presentation layer and should be done in application.
I am trying to extract XML node from SQL query. I have XML report specification in one of the column of SQL table.
I want to extract sqlText node from the XML using SQL query.
I have uploaded the xml to dropbox:
https://www.dropbox.com/sh/28xu7ifu78h6gm0/AACQS24NEjPFO0GXEI9vLuefa?dl=0
Any help would be greatly appreciated.
If you are using xml document
declare #xml xml ='<report ....</report>'
select #xml.value('(/report/queries/query/source/sqlQuery/sqlText)[1]', 'varchar(100)') as [SqlText]
Assuming that the XML data is stored in XML typed column named myXmlColumn in SQL table named myTable, you can specify the default namespace for the XPath using ;WITH XMLNAMESPACES(), for example :
;WITH XMLNAMESPACES(default 'http://developer.cognos.com/schemas/report/8.0/')
select myTable.myXmlColumn.value('(/report/queries/query/source/sqlQuery/sqlText)[1]'
, 'varchar(max)') as sqlText
If there are more than one sqlQuery node, following SQL XML query can be used
SELECT
[Query].value('.','varchar(100)') AS QueryText
FROM #xml.nodes('/report/queries/query/source/sqlQuery/sqlText') Queries([Query])
I am trying to query results as XML from Oracle db using XMLElement and XMLAgg functions which gives me results in CLOB format. Now, when I try to use this query in Data Source flow task in SSIS, I get an error as unsupported data format.
Query:
select XMLElement("root",
XMLAgg(XMLElement("person",
XMLForest(person.first_name, person.last_name)))) AS "XMLResult"
from person
Question:
How do I use this query in SSIS (2008 R2) to avoid that error or any workaround. Further I need to write the results to a file.
You will need to convert the result into VARCHAR or VARCHAR2 datatype as SSIS doesn't support the XML datatype.
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('')