2
Declare @xml = '<root><row ClassID=''99c24704-bfdb-4350-a35b-102cf5699edb'' UserID=''adsadadsada''  /><row ClassID=''99c24704-bfdb-4350-a35b-102cf5699edb'' UserID=''adsadadsada''  /></root>'

i want to perform the following:-

select * from @xml

select classid from @xml

select * from xml where classid=[somevalue]

2 Answers 2

2

You can't use * against XML you need to list the columns you want.

Declare @xml xml = 
'<root>
  <row ClassID=''99c24704-bfdb-4350-a35b-102cf5699edb'' UserID=''adsadadsada'' />
  <row ClassID=''99c24704-bfdb-4350-a35b-102cf5699edb'' UserID=''adsadadsada'' />
</root>'

select 
  N.value('@ClassID', 'uniqueidentifier') as ClassID,
  N.value('@UserID', 'varchar(50)') as UserID
from @xml.nodes('root/row') as T(N)
where N.value('@ClassID', 'uniqueidentifier') = '99c24704-bfdb-4350-a35b-102cf5699edb'
1
  • thats gr8...thnx a ton Mikael
    – lsharma
    Jun 16, 2011 at 11:34
0

this syntax is near what you were talking about:

;with myXml as
(
select 
  a.value('@ClassID', 'uniqueidentifier') as ClassID,
  a.value('@UserID', 'varchar(50)') as UserID
  from @xml.nodes('root/row') as x(a)
)
select * from myXml
where classid = '99c24704-bfdb-4350-a35b-102cf5699edb'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.