Home All Groups Group Topic Archive Search About

Predicate value when retrieving a value

Author
11 Oct 2007 7:33 PM
Loren Dummer
Is it possible to have the predicate value a variable.

Example:

DECLARE @XmlData        xml
       ,@Predicate      int
       ,@Value          nvarchar (65)


SELECT @XmlData = '<DocumentPacket>
                     <Party>
                       <Number>1000</Number>
                       <ModeOfTransportation>
                         <Code>40</Code>
                         <Description>Air</Description>
                       </ModeOfTransportation>
                     </Party>
                     <Party>
                       <Number>2000</Number>
                       <ModeOfTransportation>
                         <Code></Code>
                         <Description></Description>
                       </ModeOfTransportation>
                     </Party>
                   </DocumentPacket>'

  SET @Predicate = 1

  -- This works fine.
  SELECT @Value = @XmlData.value('(/DocumentPacket/Party/Number)[1]',
'nvarchar(65)')


  -- I want to do something like this, is this possible?
  SELECT @Value =
@XmlData.value('(/DocumentPacket/Party/Number)[sql:variable("@Predicate")]',
'nvarchar(65)')

Author
11 Oct 2007 8:23 PM
Kent Tegels
Hello Loren,

> Is it possible to have the predicate value a variable.

Sure, you almost had it:

SELECT @Value =
@XmlData.value('(/DocumentPacket/Party/Number)[sql:variable("@predicate")][1]',
'nvarchar(65)')

Thanks!
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/
Author
11 Oct 2007 10:16 PM
Loren Dummer
Thank-you, it also works for me now.

Show quote
"Kent Tegels" <kteg***@develop.com> wrote in message
news:18f2bcb129e248c9da31d6d34cd0@news.microsoft.com...
> Hello Loren,
>
>> Is it possible to have the predicate value a variable.
>
> Sure, you almost had it:
>
> SELECT @Value =
> @XmlData.value('(/DocumentPacket/Party/Number)[sql:variable("@predicate")][1]',
> 'nvarchar(65)')
>
> Thanks!
> Kent Tegels
> DevelopMentor
> http://staff.develop.com/ktegels/
>
>

AddThis Social Bookmark Button