SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Query XML data for blsnkd


Query XML data for blsnkd

Author
Message
jdbrown239
jdbrown239
Old Hand
Old Hand (310 reputation)Old Hand (310 reputation)Old Hand (310 reputation)Old Hand (310 reputation)Old Hand (310 reputation)Old Hand (310 reputation)Old Hand (310 reputation)Old Hand (310 reputation)

Group: General Forum Members
Points: 310 Visits: 409
Hi
I am try to see if there are any blanks in a node of a table that has xml data in one of the columns. The query I use is returning zero results. Any suggestions?
Select COUNT(*)from ENTITY
Where CONVERT(XML, Ent_root_xml, 0 ).value('(//UD_PQ_FLAG/node())[1]', 'VARCHAR(50)')= ''
Eirikur Eiriksson
Eirikur Eiriksson
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15372 Visits: 18613
Quite few ways of doing this, here is one
Cool

DECLARE @XML_STUFF TABLE
(
XML_ID INT IDENTITY(1,1) PRIMARY KEY CLUSTERED NOT NULL
,XML_DATA XML NOT NULL
)

INSERT INTO @XML_STUFF (XML_DATA)
VALUES
(N'<ROOT>
<ELEMENT01>
<DETAIL>HAS STUFF</DETAIL>
</ELEMENT01>
</ROOT>')
,(N'<ROOT>
<ELEMENT01>
<!-- HAS NO STUFF -->
</ELEMENT01>
</ROOT>')
,(N'<ROOT>
<ELEMENT01>
<DETAIL>HAS STUFF</DETAIL>
</ELEMENT01>
</ROOT>');

SELECT
XS.XML_ID
,DET.AIL.value('.[1]','NVARCHAR(128)') AS DETAIL_TEXT
FROM @XML_STUFF XS
OUTER APPLY XS.XML_DATA.nodes('ROOT/ELEMENT01/DETAIL') AS DET(AIL);



Results
XML_ID      DETAIL_TEXT
----------- ------------
1 HAS STUFF
2 NULL
3 HAS STUFF

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search