Get Position() Value in XML.Query
  Home FAQ Contact Sign in
microsoft.public.sqlserver.xml only
 
Advanced search
POPULAR GROUPS

more...

microsoft.public.sqlserver.xml Profile…
 Up
Get Position() Value in XML.Query         


Author: Matt
Date: Jan 24, 2007 12:03

Given the following syntax in SQL Server 2005:
Show full article (1.42Kb)
3 Comments
Re: Get Position() Value in XML.Query         


Author: markc600
Date: Jan 24, 2007 16:14

Maybe this?

select Data.Student.value('@id', 'varchar(6)') as id,
Data.Student.value('(Name)[1]', 'varchar(30)') as [name],
Data.Student.value('(Class)[1]', 'varchar(50)') as class ,
Data.Student.value('for $a in . return count($a/../*[. << $a]) +
1','int') as ndx
from @xmlvar.nodes('/Data/Student') Data(Student)
2 Comments
Re: Get Position() Value in XML.Query         


Author: Matt
Date: Jan 25, 2007 05:51

Mark,

Thanks that definitly gets me going in the right direction. Can you explain
the statement count($a/../*[. << $a]) , other than count() I get lost after
the "[".

Thanks,

Matt

hotmail.com> wrote in message
news:1169684064.504759.156860@q2g2000cwa.googlegroups.com...
> Maybe this?
>
>
> select Data.Student.value('@id', 'varchar(6)') as id,
> Data.Student.value('(Name)[1]', 'varchar(30)') as [name],
> Data.Student.value('(Class)[1]', 'varchar(50)') as class ,
> Data.Student.value('for $a in . return count($a/../*[. << $a]) +
> 1','int') as ndx
> from @xmlvar.nodes('/Data/Student') Data(Student)
>
1 Comment
Re: Get Position() Value in XML.Query         


Author: Matt
Date: Jan 29, 2007 09:58

Mark,

Thanks for the explanation but I am confused by something I am getting with
one of my queries. Using your recommended method works great on one part of
the XML I am working with but in another area the number starts at 7. If I
run different things I get different values. Any ideas? I can't post the
actual XML I am working with but I can send it to you if you would like to
see my issue with my query.

Thanks,

Matt
Show full article (1.00Kb)
no comments

RELATED THREADS
SubjectArticles qty Group
SUBSTRING in query of queriesmacromedia.coldfusion.cfml_general_discussion ·