select XML data into a variable

  • hi folks

    this is proboably a really simple problem, but i just can't see the wood for the trees here.

    i have a result set with a single column that is the result of a very simple query - what i need to do is package these up as XML into a variable

    here's some sample code to show what i want to do (it's not my production code - this is just prototyping so that i can show the issue)

    declare @results xml

    select @results=name from sysobjects for XML AUTO

    i get the error

    "the FOR XML clause is not allowed in an assignment statement"

    this must be soooooo simple, i can't seem to figure out a way to do this

    hang my head in shame

    MVDBA

  • does this help

    declare @results xml

    set @results = (select name from sysobjects for XML AUTO)

    select @results

  • genius - thank you

    MVDBA

Viewing 3 posts - 1 through 2 (of 2 total)

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