Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Using xml attribute in the where clause of a slect stateme..

 
   Database Help (Home) -> XML RSS
Next:  using value of xml attribute in a where clause  
Author Message
Andy B

External


Since: Feb 13, 2008
Posts: 215



(Msg. 1) Posted: Fri Oct 17, 2008 2:00 pm
Post subject: Using xml attribute in the where clause of a slect statement.
Archived from groups: microsoft>public>sqlserver>xml (more info?)

I have the following select/insert statement:

insert into [News].[NewsArchive] select [Article], [LastModified] from
[News].[News] where ...

In the where clause, I need to use the value of the attribute
/NewsArticle/@Date in an xpath statement. How do you do this?

 >> Stay informed about: Using xml attribute in the where clause of a slect stateme.. 
Back to top
Login to vote
Martin Honnen

External


Since: Apr 20, 2007
Posts: 48



(Msg. 2) Posted: Sat Oct 18, 2008 9:25 am
Post subject: Re: Using xml attribute in the where clause of a slect statement. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Andy B wrote:
> I have the following select/insert statement:
>
> insert into [News].[NewsArchive] select [Article], [LastModified] from
> [News].[News] where ...
>
> In the where clause, I need to use the value of the attribute
> /NewsArticle/@Date in an xpath statement. How do you do this?

Example
WHERE xmlColumnName.value('(/NewsArticle/@Date)[1]', 'datetime') =
'2008-10-18T12:00:00'

That assumes (based on the attribute name) that the Date attribute
contains a date/time value that you want to cast to an SQL Server
datetime value for instance.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

 >> Stay informed about: Using xml attribute in the where clause of a slect stateme.. 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Extract Attribute across many XML docs - I want to extract the value of the CorrelationID without having to specify the entire path. There will be over 50 different XML documents with this attribute and I would like to avoid a large number of statements to get this value. declare..

How to select an attribute value from an XML-column using .. - Hi, I have stored some XML data in a XML-column in one of my tables. It looks something like this: <Parameters> <Parameter Name="View" Value="A" /> <Parameter Name="@HistDate" Value="2007-02-12&qu...

modify() Top-level attribute nodes are not supported Error - I'm trying to return the following: <person> <personal_info> ... </personal_info> <prof_quals> ... </prof_quals> </person> The following results in an error: XQuery [#xPerson.xPerson.modify()]: Top-level att...

xml to SQL DB - We have some large existing Xml files that we'd like to store in the SQL server. We don't want to store just the Xml stream, but we rather like to build the hierarchical structure that represents the Xml in SQL and store the Xml that way. We also want...

how to store a word document in sql server - I Need help on how to store a word document in sql server.what datatype and how to convert it to store it. Pleas Help Thank you
   Database Help (Home) -> XML All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]