Thursday, March 22, 2012
buggy sql like command with wildcards to xml
create procedure MKR
@.mkrvar nvarchar(50)
AS
SELECT *
FROM QUADRA
WHERE (SUBSTRING(QUADRA, 3, 9) LIKE '%@.mkrvar%')
GO
so i call it like this on my browser :
http://mywebsite/?sql=exec MKR '57' FOR XML NESTED&root=root
is not working...oh !
http://mywebsite/?sql=SELECT * FROM QUADRA WHERE (SUBSTRING(QUADRA, 3, 9)
LIKE '%57%')FOR XML NESTED&root=root
it doesnt work too
so i trought that might be something buggy...donno...so i tried this
http://mywebsite/?sql=SELECT * FROM QUADRA WHERE (QUADRA LIKE '%57%') FOR
XML RAW&root=root
ok...it doesnt work...why ?
but this work
http://mywebsite/?sql=SELECT * FROM QUADRA WHERE (QUADRA LIKE '57') FOR XML
RAW&root=root
so...why i cant use wildcards to generate an xml ?
i need a fix or a workarround for this asap, if someone could help :D
thanks
max
% is an escape character in a URL. For example you will see spaces
converted to %20.
Try %%57%% instead.
"Antonio Max" <maxspam@.bol.com.br> wrote in message
news:eiuMJVxKEHA.3292@.TK2MSFTNGP11.phx.gbl...
>I have this stored procedure, witch works nice under the query mode
> create procedure MKR
> @.mkrvar nvarchar(50)
> AS
> SELECT *
> FROM QUADRA
> WHERE (SUBSTRING(QUADRA, 3, 9) LIKE '%@.mkrvar%')
> GO
> so i call it like this on my browser :
> http://mywebsite/?sql=exec MKR '57' FOR XML NESTED&root=root
> is not working...oh !
> http://mywebsite/?sql=SELECT * FROM QUADRA WHERE (SUBSTRING(QUADRA, 3, 9)
> LIKE '%57%')FOR XML NESTED&root=root
> it doesnt work too
> so i trought that might be something buggy...donno...so i tried this
>
> http://mywebsite/?sql=SELECT * FROM QUADRA WHERE (QUADRA LIKE '%57%') FOR
> XML RAW&root=root
> ok...it doesnt work...why ?
>
> but this work
> http://mywebsite/?sql=SELECT * FROM QUADRA WHERE (QUADRA LIKE '57') FOR
> XML
> RAW&root=root
> so...why i cant use wildcards to generate an xml ?
> i need a fix or a workarround for this asap, if someone could help :D
> thanks
> max
>
>
|||thanks a lot
forgot this;;.. eerr
anyway...it looks like this now
http://mywebsite/?sql=SELECT%20*%20F...DRA%20WHERE%20(QUADRA%20LIKE%20
'%2557%25')%20FOR%20XML%20RAW&root=root
where %25 is the % sign on url encoding char table
thanks
max
"Roger Wolter[MSFT]" <rwolter@.online.microsoft.com> wrote in message
news:#T#EIIzKEHA.892@.TK2MSFTNGP09.phx.gbl...[vbcol=seagreen]
> % is an escape character in a URL. For example you will see spaces
> converted to %20.
> Try %%57%% instead.
>
> "Antonio Max" <maxspam@.bol.com.br> wrote in message
> news:eiuMJVxKEHA.3292@.TK2MSFTNGP11.phx.gbl...
9)[vbcol=seagreen]
FOR
>
Tuesday, March 20, 2012
BUG: using FOR XML AUTO
- Windows Server 2003, Enterprise Edition.
- SQL Server 2005, Client tools (Server is in an another machine)
- VirusScan Enterprise 8.0.0
When i execute the next query:
USE AdventureWorks
SELECT * FROM Person.Contact
WHERE ContactID = 1 FOR XML AUTO
VirusScan report me this:
Pathname: C:\Documents and Settings\<user>\Local Settings\Temp\tmp5B.tmp
Detected As: Exploit-ObscuredHtml
Detection Type: Trojan
Application: SqlWb.exe
And SQL Server Management Studio:
An error occurred while executing batch. Error message is: Invalid calling
sequence: file stream must be initialized first.
*****
I apreciate any sugestion !
Thank you.I turn off the antivirus and the query work,
I reported the problem to McAfee...
"Ubeimar Vergara" wrote:
> I have installed this software:
> - Windows Server 2003, Enterprise Edition.
> - SQL Server 2005, Client tools (Server is in an another machine)
> - VirusScan Enterprise 8.0.0
> When i execute the next query:
> USE AdventureWorks
> SELECT * FROM Person.Contact
> WHERE ContactID = 1 FOR XML AUTO
> VirusScan report me this:
> Pathname: C:\Documents and Settings\<user>\Local Settings\Temp\tmp5B.tmp
> Detected As: Exploit-ObscuredHtml
> Detection Type: Trojan
> Application: SqlWb.exe
> And SQL Server Management Studio:
> An error occurred while executing batch. Error message is: Invalid calling
> sequence: file stream must be initialized first.
> *****
> I apreciate any sugestion !
> Thank you.
BUG: using FOR XML AUTO
- Windows Server 2003, Enterprise Edition.
- SQL Server 2005, Client tools (Server is in an another machine)
- VirusScan Enterprise 8.0.0
When i execute the next query:
USE AdventureWorks
SELECT * FROM Person.Contact
WHERE ContactID = 1 FOR XML AUTO
VirusScan report me this:
Pathname: C:\Documents and Settings\<user>\Local Settings\Temp\tmp5B.tmp
Detected As: Exploit-ObscuredHtml
Detection Type: Trojan
Application: SqlWb.exe
And SQL Server Management Studio:
An error occurred while executing batch. Error message is: Invalid calling
sequence: file stream must be initialized first.
*****
I apreciate any sugestion !
Thank you.TURN OFF anti-virus software on the server!!
A properly configured SQL Server 'should' not need anti-virus software
installed on the server.
--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Ubeimar Vergara" <Ubeimar Vergara@.discussions.microsoft.com> wrote in
message news:9CD7E5A0-C308-44C6-A3EA-A0B4CC2D346F@.microsoft.com...
>I have installed this software:
> - Windows Server 2003, Enterprise Edition.
> - SQL Server 2005, Client tools (Server is in an another machine)
> - VirusScan Enterprise 8.0.0
> When i execute the next query:
> USE AdventureWorks
> SELECT * FROM Person.Contact
> WHERE ContactID = 1 FOR XML AUTO
> VirusScan report me this:
> Pathname: C:\Documents and Settings\<user>\Local Settings\Temp\tmp5B.tmp
> Detected As: Exploit-ObscuredHtml
> Detection Type: Trojan
> Application: SqlWb.exe
> And SQL Server Management Studio:
> An error occurred while executing batch. Error message is: Invalid calling
> sequence: file stream must be initialized first.
> *****
> I apreciate any sugestion !
> Thank you.|||"Ubeimar Vergara" <Ubeimar Vergara@.discussions.microsoft.com> wrote in
message news:9CD7E5A0-C308-44C6-A3EA-A0B4CC2D346F@.microsoft.com...
>I have installed this software:
> - Windows Server 2003, Enterprise Edition.
> - SQL Server 2005, Client tools (Server is in an another machine)
> - VirusScan Enterprise 8.0.0
> When i execute the next query:
> USE AdventureWorks
> SELECT * FROM Person.Contact
> WHERE ContactID = 1 FOR XML AUTO
> VirusScan report me this:
> Pathname: C:\Documents and Settings\<user>\Local Settings\Temp\tmp5B.tmp
> Detected As: Exploit-ObscuredHtml
> Detection Type: Trojan
> Application: SqlWb.exe
> And SQL Server Management Studio:
> An error occurred while executing batch. Error message is: Invalid calling
> sequence: file stream must be initialized first.
>
Sounds like a bug in your Antivirus program interfering with the operation
of Management Studio on your client computer.
David|||I turn off the antivirus and the query work,
I reported the problem to McAfee...
"Ubeimar Vergara" wrote:
> I have installed this software:
> - Windows Server 2003, Enterprise Edition.
> - SQL Server 2005, Client tools (Server is in an another machine)
> - VirusScan Enterprise 8.0.0
> When i execute the next query:
> USE AdventureWorks
> SELECT * FROM Person.Contact
> WHERE ContactID = 1 FOR XML AUTO
> VirusScan report me this:
> Pathname: C:\Documents and Settings\<user>\Local Settings\Temp\tmp5B.tmp
> Detected As: Exploit-ObscuredHtml
> Detection Type: Trojan
> Application: SqlWb.exe
> And SQL Server Management Studio:
> An error occurred while executing batch. Error message is: Invalid calling
> sequence: file stream must be initialized first.
> *****
> I apreciate any sugestion !
> Thank you.sql
Monday, March 19, 2012
Bug using FOR XML AUTO with columns with type char(1)
Having some problems with generating xml with "FOR XML AUTO". Rows with
a column with a value char(0) seems to terminate the row!
Try to run the following:
SELECT
*
FROM (
SELECT
1 AS orderItemId,
1 AS orderId,
CHAR(0) AS orderItemStatus --CHAR(0) terminates row!
UNION
SELECT
2 AS orderItemId,
1 AS orderId,
CHAR(49) AS orderItemStatus
) AS orderItem
FOR XML AUTO
Generates:
<orderItem orderItemId="1" orderId="1" orderItemStatus="
Should be(?):
<orderItem orderItemId="1" orderId="1" orderItemStatus=" "/><orderItem
orderItemId="2" orderId="1" orderItemStatus="1"/>
Anyone seen this before?
Regards, Nils
CHAR(0) is not a valid XML character. In FOR XML, we do not detect invalid
characters for performance reasons, so you will pass the XML anyway.
Depending on what the client code uses to read the XML, it may see the
CHAR(0) and decide that it is the end of the string (for instance, if the
client code uses the standard C/C++ string types).
So the recommendation is: Do not generate XML containing invalid characters
such as CHAR(0) since they are not supported by compliant XML parsers and
may result in other unforeseen behaviour.
Best regards
Michael
<nilsflemstrom@.gmail.com> wrote in message
news:1125047051.277443.138730@.z14g2000cwz.googlegr oups.com...
> Hello,
> Having some problems with generating xml with "FOR XML AUTO". Rows with
> a column with a value char(0) seems to terminate the row!
> Try to run the following:
> SELECT
> *
> FROM (
> SELECT
> 1 AS orderItemId,
> 1 AS orderId,
> CHAR(0) AS orderItemStatus --CHAR(0) terminates row!
> UNION
> SELECT
> 2 AS orderItemId,
> 1 AS orderId,
> CHAR(49) AS orderItemStatus
> ) AS orderItem
> FOR XML AUTO
> Generates:
> <orderItem orderItemId="1" orderId="1" orderItemStatus="
> Should be(?):
> <orderItem orderItemId="1" orderId="1" orderItemStatus=" "/><orderItem
> orderItemId="2" orderId="1" orderItemStatus="1"/>
> Anyone seen this before?
> Regards, Nils
>
Bug using FOR XML AUTO with columns with type char(1)
Having some problems with generating xml with "FOR XML AUTO". Rows with
a column with a value char(0) seems to terminate the row!
Try to run the following:
SELECT
*
FROM (
SELECT
1 AS orderItemId,
1 AS orderId,
CHAR(0) AS orderItemStatus --CHAR(0) terminates row!
UNION
SELECT
2 AS orderItemId,
1 AS orderId,
CHAR(49) AS orderItemStatus
) AS orderItem
FOR XML AUTO
Generates:
<orderItem orderItemId="1" orderId="1" orderItemStatus="
Should be(?):
<orderItem orderItemId="1" orderId="1" orderItemStatus=" "/><orderItem
orderItemId="2" orderId="1" orderItemStatus="1"/>
Anyone seen this before?
Regards, NilsCHAR(0) is not a valid XML character. In FOR XML, we do not detect invalid
characters for performance reasons, so you will pass the XML anyway.
Depending on what the client code uses to read the XML, it may see the
CHAR(0) and decide that it is the end of the string (for instance, if the
client code uses the standard C/C++ string types).
So the recommendation is: Do not generate XML containing invalid characters
such as CHAR(0) since they are not supported by compliant XML parsers and
may result in other unforeseen behaviour.
Best regards
Michael
<nilsflemstrom@.gmail.com> wrote in message
news:1125047051.277443.138730@.z14g2000cwz.googlegroups.com...
> Hello,
> Having some problems with generating xml with "FOR XML AUTO". Rows with
> a column with a value char(0) seems to terminate the row!
> Try to run the following:
> SELECT
> *
> FROM (
> SELECT
> 1 AS orderItemId,
> 1 AS orderId,
> CHAR(0) AS orderItemStatus --CHAR(0) terminates row!
> UNION
> SELECT
> 2 AS orderItemId,
> 1 AS orderId,
> CHAR(49) AS orderItemStatus
> ) AS orderItem
> FOR XML AUTO
> Generates:
> <orderItem orderItemId="1" orderId="1" orderItemStatus="
> Should be(?):
> <orderItem orderItemId="1" orderId="1" orderItemStatus=" "/><orderItem
> orderItemId="2" orderId="1" orderItemStatus="1"/>
> Anyone seen this before?
> Regards, Nils
>
Thursday, March 8, 2012
Bug in Report Server?
I am running a report using RS2005. It connects to a web service using the XML data source. It works correctly in my development environment. When I put it up on the server and run the report, I get the error message:
If I run the web service from the server, it returns correct data, so I know error is not coming from my web service. The only answer I can think of is that there is a bug in the Report Server's or XML Data Source's code.
Has anyone else seen this problem?
Thank you,
Jessica
Hi Jessica, could you please repro the bug and send me most recent RS logs to almineev. At microsoft. Com.
RS logs are located at location similar to this one: C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\LogFiles
|||Jessica, did you ever find out the solution for your problem? I am experiencing a similar issue now.
Thanks,
James
|||It hapened to me, more or less the same.For what I know it can be a problem with the default values of the
Report Parameters... they should not be originated by a query.
I had this problem and puting this as static or calculated values solved the issue...
Not the best way as by default the user's are not getting the data shown, but that's a solution.
Hope Microsoft solves the issue.. as this is a serious bug.
Regards,
Jose|||
Our problem was two report items on top of each other. Once we moved one of them over by just a little bit, the error went away.
I'm assuming it was something in the server code that wasn't handling the scenario of the same positional coordinates being inserted into a hash table, but that's just a guess.
We solved it by recreating the report one item at a time, uploading after each item. When we layered the second item on top of the first, that's when we received that message.
Good luck with everyone else trying to get this to work!
-Jessica
Bug in Report Server?
I am running a report using RS2005. It connects to a web service using the XML data source. It works correctly in my development environment. When I put it up on the server and run the report, I get the error message:
If I run the web service from the server, it returns correct data, so I know error is not coming from my web service. The only answer I can think of is that there is a bug in the Report Server's or XML Data Source's code.
Has anyone else seen this problem?
Thank you,
Jessica
Hi Jessica, could you please repro the bug and send me most recent RS logs to almineev. At microsoft. Com.
RS logs are located at location similar to this one: C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\LogFiles
|||Jessica, did you ever find out the solution for your problem? I am experiencing a similar issue now.
Thanks,
James
|||It hapened to me, more or less the same.For what I know it can be a problem with the default values of the
Report Parameters... they should not be originated by a query.
I had this problem and puting this as static or calculated values solved the issue...
Not the best way as by default the user's are not getting the data shown, but that's a solution.
Hope Microsoft solves the issue.. as this is a serious bug.
Regards,
Jose|||
Our problem was two report items on top of each other. Once we moved one of them over by just a little bit, the error went away.
I'm assuming it was something in the server code that wasn't handling the scenario of the same positional coordinates being inserted into a hash table, but that's just a guess.
We solved it by recreating the report one item at a time, uploading after each item. When we layered the second item on top of the first, that's when we received that message.
Good luck with everyone else trying to get this to work!
-Jessica
Bug in Report Server?
I am running a report using RS2005. It connects to a web service using the XML data source. It works correctly in my development environment. When I put it up on the server and run the report, I get the error message:
If I run the web service from the server, it returns correct data, so I know error is not coming from my web service. The only answer I can think of is that there is a bug in the Report Server's or XML Data Source's code.
Has anyone else seen this problem?
Thank you,
Jessica
Hi Jessica, could you please repro the bug and send me most recent RS logs to almineev. At microsoft. Com.
RS logs are located at location similar to this one: C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\LogFiles
|||Jessica, did you ever find out the solution for your problem? I am experiencing a similar issue now.
Thanks,
James
|||It hapened to me, more or less the same.For what I know it can be a problem with the default values of the Report Parameters... they should not be originated by a query.
I had this problem and puting this as static or calculated values solved the issue...
Not the best way as by default the user's are not getting the data shown, but that's a solution.
Hope Microsoft solves the issue.. as this is a serious bug.
Regards,
Jose|||
Our problem was two report items on top of each other. Once we moved one of them over by just a little bit, the error went away.
I'm assuming it was something in the server code that wasn't handling the scenario of the same positional coordinates being inserted into a hash table, but that's just a guess.
We solved it by recreating the report one item at a time, uploading after each item. When we layered the second item on top of the first, that's when we received that message.
Good luck with everyone else trying to get this to work!
-Jessica
Bug in Report Server?
I am running a report using RS2005. It connects to a web service using the XML data source. It works correctly in my development environment. When I put it up on the server and run the report, I get the error message:
If I run the web service from the server, it returns correct data, so I know error is not coming from my web service. The only answer I can think of is that there is a bug in the Report Server's or XML Data Source's code.
Has anyone else seen this problem?
Thank you,
Jessica
Hi Jessica, could you please repro the bug and send me most recent RS logs to almineev. At microsoft. Com.
RS logs are located at location similar to this one: C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\LogFiles
|||Jessica, did you ever find out the solution for your problem? I am experiencing a similar issue now.
Thanks,
James
|||It hapened to me, more or less the same.For what I know it can be a problem with the default values of the
Report Parameters... they should not be originated by a query.
I had this problem and puting this as static or calculated values solved the issue...
Not the best way as by default the user's are not getting the data shown, but that's a solution.
Hope Microsoft solves the issue.. as this is a serious bug.
Regards,
Jose|||
Our problem was two report items on top of each other. Once we moved one of them over by just a little bit, the error went away.
I'm assuming it was something in the server code that wasn't handling the scenario of the same positional coordinates being inserted into a hash table, but that's just a guess.
We solved it by recreating the report one item at a time, uploading after each item. When we layered the second item on top of the first, that's when we received that message.
Good luck with everyone else trying to get this to work!
-Jessica
Tuesday, February 14, 2012
Break XML into Columns
Hi,
I have a XML of the structure,
<XMLSET>
<Column name="Header">hello</Column>
<Column name="Header1">hello</Column>
<Column name="Header2">hello</Column>
</XMLSET>
in my database (SQL - 2k5). Now I want to split it in a manner that yields me this output;
Header Header1 Header2
Hello Hello Hello
Any pointers on how to go about this ?
Thanks in Advance,
declare @.x xml
set @.x='<XMLSET>
<Column name="Header">hello</Column>
<Column name="Header1">hello1</Column>
<Column name="Header2">hello2</Column>
</XMLSET>'
select r.value('(./Column[@.name="Header"])[1]','varchar(10)') as Header,
r.value('(./Column[@.name="Header1"])[1]','varchar(10)') as Header1,
r.value('(./Column[@.name="Header2"])[1]','varchar(10)') as Header2
from @.x.nodes('/XMLSET') as x(r)
Thanks for the reply....
A small query here..... Instead of hard coding the name of the column as Header, Header1 is there a way we can have the headers displayed dynamically... In short the following query will always return header, header1 and so. How to get it displayed dynamically?
select r.value('(./Column[@.name="Head"])[1]','varchar(10)') as Header,
r.value('(./Column[@.name="Headr1"])[1]','varchar(10)') as Header1,
r.value('(./Column[@.name="Headr2"])[1]','varchar(10)') as Header2
from @.x.nodes('/XMLSET') as x(r)
Thanks again for the reply....
|||If you want to have dynamic column names you'll have to use dynamic SQL.
Note that you can use variables for your search criteria as below.
declare @.h1 varchar(10)
declare @.h2 varchar(10)
declare @.h3 varchar(10)
set @.h1='Header'
set @.h2='Header1'
set @.h3='Header2'
declare @.x xml
set @.x='<XMLSET>
<Column name="Header">hello</Column>
<Column name="Header1">hello1</Column>
<Column name="Header2">hello2</Column>
</XMLSET>'
select r.value('(./Column[@.name=sql:variable("@.h1")])[1]','varchar(10)') as Header,
r.value('(./Column[@.name=sql:variable("@.h2")])[1]','varchar(10)') as Header1,
r.value('(./Column[@.name=sql:variable("@.h3")])[1]','varchar(10)') as Header2
from @.x.nodes('/XMLSET') as x(r)
Hi
I am processing xml in sql server 2005. The values are stored in a column as xml datatype. How to query the data that is in the column. This is the structure of the xml.
'<skill>
<Coach type="AA">false</Coach>
<CDT type="AA">false</CDT>
<DIT type="AA">false</DIT>
<FSA type="AA">false</FSA>
<LMR type="AA">false</LMR>
<ROSPA type="Additional">false</ROSPA>
<IAM type="Additional">false</IAM>
<Diamond type="Additional">false</Diamond>
<DipDI type="Additional">false</DipDI>
<BTEC type="Additional">false</BTEC>
<QEF type="Additional">
<member>false</member>
<certificatenumber />
<level />
</QEF>
<BTec type="Additional">false</BTec>
</skill>'
Thanks
Srini
|||Can you be bit specific here ?
You want the data in the XML as columns is it ?
|||The data is in the xml field of a table. The xml contains the skills of a candidate. I need to access the skill set values like CDT=false, DIT = false, and additional qualifications, if any, have to be accessed.
Thanks,
Srini
|||Not sure if I got ur requirement clear, but I infer you wanted to break open the XML nodes as columns. Create a table like this, insert the two values and then run the query.
create table test
(x xml)
go
insert test values(
N'<XMLDATA>
<COLUMNS>
<Column name="Val1">sdf \r\nsdfsdfs sdfsdf</Column>
<Column name="Val2"> 2 </Column>
<Column name="Val3"> 3 </Column>
<Column name="Val4"> Test0 </Column>
<Column name="Val5"> Test1 </Column>
<Column name="Val6"> Test2 </Column>
<Column name="Val7"> Test3 </Column>
<Column name="Val8"> Test4 </Column>
</COLUMNS>
</XMLDATA>')
go
insert test values(
N'<XMLDATA>
<COLUMNS>
<Column name="Val1">sdf \r\nsdfsdfs sdfsdf</Column>
<Column name="Val2"> 2 </Column>
<Column name="Val3"> 3 </Column>
<Column name="Val4"> Test0 </Column>
<Column name="Val5"> Test1 </Column>
<Column name="Val6"> Test2 </Column>
<Column name="Val7"> Test3 </Column>
<Column name="Val8"> Test4 </Column>
</COLUMNS>
</XMLDATA>')
go
SELECT ref.value('@.name', 'varchar(50)') Header, ref.value('data(.)', 'varchar(50)') Val
FROM test cross apply x.nodes('/XMLDATA/COLUMNS/Column') as x(ref)
Hope that helps...
Break XML into Columns
Hi,
I have a XML of the structure,
<XMLSET>
<Column name="Header">hello</Column>
<Column name="Header1">hello</Column>
<Column name="Header2">hello</Column>
</XMLSET>
in my database (SQL - 2k5). Now I want to split it in a manner that yields me this output;
Header Header1 Header2
Hello Hello Hello
Any pointers on how to go about this ?
Thanks in Advance,
declare @.x xml
set @.x='<XMLSET>
<Column name="Header">hello</Column>
<Column name="Header1">hello1</Column>
<Column name="Header2">hello2</Column>
</XMLSET>'
select r.value('(./Column[@.name="Header"])[1]','varchar(10)') as Header,
r.value('(./Column[@.name="Header1"])[1]','varchar(10)') as Header1,
r.value('(./Column[@.name="Header2"])[1]','varchar(10)') as Header2
from @.x.nodes('/XMLSET') as x(r)
Thanks for the reply....
A small query here..... Instead of hard coding the name of the column as Header, Header1 is there a way we can have the headers displayed dynamically... In short the following query will always return header, header1 and so. How to get it displayed dynamically?
select r.value('(./Column[@.name="Head"])[1]','varchar(10)') as Header,
r.value('(./Column[@.name="Headr1"])[1]','varchar(10)') as Header1,
r.value('(./Column[@.name="Headr2"])[1]','varchar(10)') as Header2
from @.x.nodes('/XMLSET') as x(r)
Thanks again for the reply....
|||If you want to have dynamic column names you'll have to use dynamic SQL.
Note that you can use variables for your search criteria as below.
declare @.h1 varchar(10)
declare @.h2 varchar(10)
declare @.h3 varchar(10)
set @.h1='Header'
set @.h2='Header1'
set @.h3='Header2'
declare @.x xml
set @.x='<XMLSET>
<Column name="Header">hello</Column>
<Column name="Header1">hello1</Column>
<Column name="Header2">hello2</Column>
</XMLSET>'
select r.value('(./Column[@.name=sql:variable("@.h1")])[1]','varchar(10)') as Header,
r.value('(./Column[@.name=sql:variable("@.h2")])[1]','varchar(10)') as Header1,
r.value('(./Column[@.name=sql:variable("@.h3")])[1]','varchar(10)') as Header2
from @.x.nodes('/XMLSET') as x(r)
Hi
I am processing xml in sql server 2005. The values are stored in a column as xml datatype. How to query the data that is in the column. This is the structure of the xml.
'<skill>
<Coach type="AA">false</Coach>
<CDT type="AA">false</CDT>
<DIT type="AA">false</DIT>
<FSA type="AA">false</FSA>
<LMR type="AA">false</LMR>
<ROSPA type="Additional">false</ROSPA>
<IAM type="Additional">false</IAM>
<Diamond type="Additional">false</Diamond>
<DipDI type="Additional">false</DipDI>
<BTEC type="Additional">false</BTEC>
<QEF type="Additional">
<member>false</member>
<certificatenumber />
<level />
</QEF>
<BTec type="Additional">false</BTec>
</skill>'
Thanks
Srini
|||Can you be bit specific here ?
You want the data in the XML as columns is it ?
|||The data is in the xml field of a table. The xml contains the skills of a candidate. I need to access the skill set values like CDT=false, DIT = false, and additional qualifications, if any, have to be accessed.
Thanks,
Srini
|||Not sure if I got ur requirement clear, but I infer you wanted to break open the XML nodes as columns. Create a table like this, insert the two values and then run the query.
create table test
(x xml)
go
insert test values(
N'<XMLDATA>
<COLUMNS>
<Column name="Val1">sdf \r\nsdfsdfs sdfsdf</Column>
<Column name="Val2"> 2 </Column>
<Column name="Val3"> 3 </Column>
<Column name="Val4"> Test0 </Column>
<Column name="Val5"> Test1 </Column>
<Column name="Val6"> Test2 </Column>
<Column name="Val7"> Test3 </Column>
<Column name="Val8"> Test4 </Column>
</COLUMNS>
</XMLDATA>')
go
insert test values(
N'<XMLDATA>
<COLUMNS>
<Column name="Val1">sdf \r\nsdfsdfs sdfsdf</Column>
<Column name="Val2"> 2 </Column>
<Column name="Val3"> 3 </Column>
<Column name="Val4"> Test0 </Column>
<Column name="Val5"> Test1 </Column>
<Column name="Val6"> Test2 </Column>
<Column name="Val7"> Test3 </Column>
<Column name="Val8"> Test4 </Column>
</COLUMNS>
</XMLDATA>')
go
SELECT ref.value('@.name', 'varchar(50)') Header, ref.value('data(.)', 'varchar(50)') Val
FROM test cross apply x.nodes('/XMLDATA/COLUMNS/Column') as x(ref)
Hope that helps...
Break XML into Columns
Hi,
I have a XML of the structure,
<XMLSET>
<Column name="Header">hello</Column>
<Column name="Header1">hello</Column>
<Column name="Header2">hello</Column>
</XMLSET>
in my database (SQL - 2k5). Now I want to split it in a manner that yields me this output;
Header Header1 Header2
Hello Hello Hello
Any pointers on how to go about this ?
Thanks in Advance,
declare @.x xml
set @.x='<XMLSET>
<Column name="Header">hello</Column>
<Column name="Header1">hello1</Column>
<Column name="Header2">hello2</Column>
</XMLSET>'
select r.value('(./Column[@.name="Header"])[1]','varchar(10)') as Header,
r.value('(./Column[@.name="Header1"])[1]','varchar(10)') as Header1,
r.value('(./Column[@.name="Header2"])[1]','varchar(10)') as Header2
from @.x.nodes('/XMLSET') as x(r)
Thanks for the reply....
A small query here..... Instead of hard coding the name of the column as Header, Header1 is there a way we can have the headers displayed dynamically... In short the following query will always return header, header1 and so. How to get it displayed dynamically?
select r.value('(./Column[@.name="Head"])[1]','varchar(10)') as Header,
r.value('(./Column[@.name="Headr1"])[1]','varchar(10)') as Header1,
r.value('(./Column[@.name="Headr2"])[1]','varchar(10)') as Header2
from @.x.nodes('/XMLSET') as x(r)
Thanks again for the reply....
|||If you want to have dynamic column names you'll have to use dynamic SQL.
Note that you can use variables for your search criteria as below.
declare @.h1 varchar(10)
declare @.h2 varchar(10)
declare @.h3 varchar(10)
set @.h1='Header'
set @.h2='Header1'
set @.h3='Header2'
declare @.x xml
set @.x='<XMLSET>
<Column name="Header">hello</Column>
<Column name="Header1">hello1</Column>
<Column name="Header2">hello2</Column>
</XMLSET>'
select r.value('(./Column[@.name=sql:variable("@.h1")])[1]','varchar(10)') as Header,
r.value('(./Column[@.name=sql:variable("@.h2")])[1]','varchar(10)') as Header1,
r.value('(./Column[@.name=sql:variable("@.h3")])[1]','varchar(10)') as Header2
from @.x.nodes('/XMLSET') as x(r)
Hi
I am processing xml in sql server 2005. The values are stored in a column as xml datatype. How to query the data that is in the column. This is the structure of the xml.
'<skill>
<Coach type="AA">false</Coach>
<CDT type="AA">false</CDT>
<DIT type="AA">false</DIT>
<FSA type="AA">false</FSA>
<LMR type="AA">false</LMR>
<ROSPA type="Additional">false</ROSPA>
<IAM type="Additional">false</IAM>
<Diamond type="Additional">false</Diamond>
<DipDI type="Additional">false</DipDI>
<BTEC type="Additional">false</BTEC>
<QEF type="Additional">
<member>false</member>
<certificatenumber />
<level />
</QEF>
<BTec type="Additional">false</BTec>
</skill>'
Thanks
Srini
|||Can you be bit specific here ?
You want the data in the XML as columns is it ?
|||The data is in the xml field of a table. The xml contains the skills of a candidate. I need to access the skill set values like CDT=false, DIT = false, and additional qualifications, if any, have to be accessed.
Thanks,
Srini
|||Not sure if I got ur requirement clear, but I infer you wanted to break open the XML nodes as columns. Create a table like this, insert the two values and then run the query.
create table test
(x xml)
go
insert test values(
N'<XMLDATA>
<COLUMNS>
<Column name="Val1">sdf \r\nsdfsdfs sdfsdf</Column>
<Column name="Val2"> 2 </Column>
<Column name="Val3"> 3 </Column>
<Column name="Val4"> Test0 </Column>
<Column name="Val5"> Test1 </Column>
<Column name="Val6"> Test2 </Column>
<Column name="Val7"> Test3 </Column>
<Column name="Val8"> Test4 </Column>
</COLUMNS>
</XMLDATA>')
go
insert test values(
N'<XMLDATA>
<COLUMNS>
<Column name="Val1">sdf \r\nsdfsdfs sdfsdf</Column>
<Column name="Val2"> 2 </Column>
<Column name="Val3"> 3 </Column>
<Column name="Val4"> Test0 </Column>
<Column name="Val5"> Test1 </Column>
<Column name="Val6"> Test2 </Column>
<Column name="Val7"> Test3 </Column>
<Column name="Val8"> Test4 </Column>
</COLUMNS>
</XMLDATA>')
go
SELECT ref.value('@.name', 'varchar(50)') Header, ref.value('data(.)', 'varchar(50)') Val
FROM test cross apply x.nodes('/XMLDATA/COLUMNS/Column') as x(ref)
Hope that helps...