Reading xml string

  • Draft

    submitted

    delivered

    I want to pass this value as XML String to a SP and read back the values

    in such a way that i am going write three conditions like.

    IF @Condition ='DRAFT'

    BEGIN

    END

    IF @Condition ='SUBMITTED'

    BEGIN

    END

    IF @Condition =DELIVERED

    BEGIN

    END

    Please help me![/font]

  • I'm sure there's more to the story. Why not just pass the Condition value in as a varchar parameter? Are there other attributes in your XML that you want to deal with? Are you trying to pass a table into a procedure?

    What does your XML look like?

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • DRAFT

  • I don't think you post showed up as you expected. You may want to use the 'Preview' option before posting.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Hi Sirish,

    the first "issue": if you're posting xml data please use the [ code="xml" ] tag without spaces. This site has some difficulties to display xml structure properly if xml data are not qualified properly.

    Regarding your question:

    The following code snippet may help you to get your requirement resolved:

    DECLARE @xml XML

    SELECT @xml='

    Draft

    submitted

    delivered'

    IF (SELECT @xml.exist('/MessageStatus/Status[.="Draft"]'))=1

    BEGIN

    SELECT 'path 1'

    END

    IF (SELECT @xml.exist('/MessageStatus/Status[.="submitted"]'))=1

    BEGIN

    SELECT 'path 2'

    END

    IF (SELECT @xml.exist('/MessageStatus/Status[.="delivered"]'))=1

    BEGIN

    SELECT 'path 3'

    END



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply