Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Textfield contains XML

Author  Topic 

xrum
Yak Posting Veteran

87 Posts

Posted - 2010-10-22 : 13:31:17
Hi,

i have a text field that contains some XML,

is it at all possible to query a specific XML noce via SQL?

like for example:

field name: content

<root><Default><ClassTitle>test class</ClassTitle> <ClassDescription>description</ClassDescription> <Location>Bethesda</Location> </Default> </root>

i need to only find records that have Location node = Bethesda....

right now this is what i have...

select top 5 cast(content_html as XML) as xmldoc , *
from content
where content_status = 'A' and content_type=3333
and end_date >= getdate()
and folder_id != 71682
and
xmldoc.value('//Location') = 'Bethesda'

but i keep getting:


Cannot find either column "xmldoc" or the user-defined function or aggregate "xmldoc.value", or the name is ambiguous.

xrum
Yak Posting Veteran

87 Posts

Posted - 2010-10-22 : 17:38:43
this is what my query looks like:

select top 5 cast(content_html as xml) as [prodxml], prodxml.value('data(ClassTemplate[1]', 'nvarchar(max) ') as prod2 from content where end_date >= getdate() and folder_id != 71682

and i keep getting:

Msg 4121, Level 16, State 1, Line 1 Cannot find either column "prodxml" or the user-defined function or aggregate "prodxml.value", or the name is ambiguous.

what am i doing wrong??
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-23 : 01:49:27
are you using sql 2005?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -