insert xml into string variable

  • is there a way where i can using "for xml" to create a query which will give me xml, and i will be able to store it in a varibale like @xmlstr a nvarchar(1000)?

    Thanks

    Peleg

  • Simple answer: yes.

    Example (using AdventureWorks):

    DECLARE @xmlstr nvarchar(1000)

    SET @xmlstr =

    (SELECT top 1 *

    FROM HumanResources.Shift

    FOR xml auto, elements)

    SELECT @xmlstr

    /*Result set (reformatted manually):

    <HumanResources.Shift>

    <ShiftID>1</ShiftID>

    <Name>Day</Name>

    <StartTime>1900-01-01T07:00:00</StartTime>

    <EndTime>1900-01-01T15:00:00</EndTime>

    <ModifiedDate>1998-06-01T00:00:00</ModifiedDate>

    </HumanResources.Shift> */



    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 2 posts - 1 through 1 (of 1 total)

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