Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Tue, 20 May 2008 12:21:35 -0700,    group: microsoft.public.xml        back       


Variable in XQUERY   
Hello,
I have a XML as below:

declare @doc2 xml
SET @doc2 = '<?xml version="1.0" ?> 
<p1: Domains_and_Emails xmlns:p1="LDAP">
  <Domain>
    <UnixEmail>
      <uid>info</uid>
      <Password>xyz</Password>
      <EmailAccount>info@xyz.com</EmailAccount>
    </UnixEmail>
</Domain>
</p1: Domains_and_Emails>'

and I am using the xml.nodes function to get the XML at the required 
position as below:

SELECT 
  tab.col.value('uid[1]','VARCHAR(20)')AS uid
  FROM @doc2.nodes('declare namespace p1="LDAP"; //p1: 
Domains_and_Emails/Domain[1]/UnixEmail[1]') tab(col)

In the above example, how would I replace the static literal "//p1: 
Domains_and_Emails/Domain[1]/UnixEmail[1]" with a variable?. basically, I 
need to pass a value for that string via a variable..

Can someone help?

Thanks,
Ganesh
date: Tue, 20 May 2008 12:21:35 -0700   author:   Ganesh Muthuvelu

Re: Variable in XQUERY   
"Ganesh Muthuvelu"  wrote in 
message news:CCB34C12-0D42-445E-A85F-F63656A889F1@microsoft.com...
> Hello,
> I have a XML as below:
>
> declare @doc2 xml
> SET @doc2 = '<?xml version="1.0" ?>
> <p1: Domains_and_Emails xmlns:p1="LDAP">
>  <Domain>
>    <UnixEmail>
>      <uid>info</uid>
>      <Password>xyz</Password>
>      <EmailAccount>info@xyz.com</EmailAccount>
>    </UnixEmail>
> </Domain>
> </p1: Domains_and_Emails>'
>
> and I am using the xml.nodes function to get the XML at the required
> position as below:
>
> SELECT
>  tab.col.value('uid[1]','VARCHAR(20)')AS uid
>  FROM @doc2.nodes('declare namespace p1="LDAP"; //p1:
> Domains_and_Emails/Domain[1]/UnixEmail[1]') tab(col)
>
> In the above example, how would I replace the static literal "//p1:
> Domains_and_Emails/Domain[1]/UnixEmail[1]" with a variable?. basically, I
> need to pass a value for that string via a variable..
>
> Can someone help?
>
> Thanks,
> Ganesh
>
>
As far as I understaqnd you can't, the standard workaround in to construct 
the SQL statement dynamically and execute using sp_ExecuteSQL.
You may wish to try microsoft.public.sqlserver.xml for these types of 
questions.

-- 

Joe Fawcett (MVP - XML)

http://joe.fawcett.name
date: Wed, 21 May 2008 08:15:14 +0100   author:   Joe Fawcett am

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us