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
 Doubts

Author  Topic 

sital
Yak Posting Veteran

89 Posts

Posted - 2009-01-25 : 06:25:36
I have doubt in the following query.

select id,xval from #sub where xval.value('(/subscription/myid)[1]','varchar(9)')=N'12345'

This query searches for the XML record which contains the value as '12345'.

Why should I write [1] in the above query? Is it necessary to write [1]?

Is there any other way in which this can be done?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-01-25 : 08:07:36
Yes, the [1] is necessary as the error message says if you run the query without it.

For searching XML with t-sql variables, see http://weblogs.sqlteam.com/peterl/archive/2008/09/01/Updated-XML-search-test-case-with-variables.aspx
and http://weblogs.sqlteam.com/peterl/archive/2008/03/26/Some-XML-search-approaches.aspx


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

sital
Yak Posting Veteran

89 Posts

Posted - 2009-01-26 : 23:00:36
quote:
Originally posted by Peso

Yes, the [1] is necessary as the error message says if you run the query without it.

For searching XML with t-sql variables, see http://weblogs.sqlteam.com/peterl/archive/2008/09/01/Updated-XML-search-test-case-with-variables.aspx
and http://weblogs.sqlteam.com/peterl/archive/2008/03/26/Some-XML-search-approaches.aspx


E 12°55'05.63"
N 56°04'39.26"





Instead of [1] can we use some other digits?If yes, what digits can be replaced in the place of [1]?
What is the need for using the digits?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-26 : 23:44:43
value requires a singleton node. which is why we need to use [1],[2],.... [1] means first nodeset matching name
Go to Top of Page

sital
Yak Posting Veteran

89 Posts

Posted - 2009-01-27 : 05:02:12
quote:
Originally posted by visakh16

value requires a singleton node. which is why we need to use [1],[2],.... [1] means first nodeset matching name



Thanks sir.


When I try to give [1] it is giving me error?

So in which cases I can use [1] and where can I use [2]?

Actually I m just learning SQL server so can you please give me detailed information I am very confused with the use of XML datatype in SQL Server. That 's why I m getting many doubts.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-27 : 08:43:57
can you show your code? [1],[2],... represents the position of nodeset, so what you use depends on which node elements value you're interested in.
Go to Top of Page

sital
Yak Posting Veteran

89 Posts

Posted - 2009-01-27 : 11:18:14
quote:
Originally posted by visakh16

can you show your code? [1],[2],... represents the position of nodeset, so what you use depends on which node elements value you're interested in.



Actually I have deleted that file. So I cannot post it in the forum.
Sorry.
Thanks a lot for helping out in all my posts in the forum.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-27 : 12:11:23
no problem..
Go to Top of Page
   

- Advertisement -