To create a fix column name for XML

  • Hi,

    With "FOR XML AUTO", SQL 2005 returns XML with random generated column name (like XML_F2412216-XXX-....). Is there a way to return a fixed column name? Thanks.

    Chris

  • I believe you only get those if you don't give a column an alias, or if you have duplicate aliases. Make sure that those columns have actual names (or aliases if the name is a duplicate of some other column)

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Hi Matt,

    Thanks for help. I have something like:

    select a

    b,

    c,....

    from tbl1

    inner join ....

    for XML auto

    in my procedure. When I run it, it return:

    XML_Frwrw........ --> column name

    XML data

    If I add "TYPE" at end of AUTO:

    ................. -> no column name

    XML data

    How could I make it to have somthing like:

    Request ---> column name

    XML data

    That way front end knows return column name, thanks.

    Chris

  • Wow. Took me trying this on my end to see whic column you're talking about. Here's one way to do what you're looking for:

    Select (

    select a,

    b,

    c,....

    from tbl1

    inner join ....

    for XML auto,TYPE

    ) as REQUEST

    That being said - if you're spitting out XML - your front-ends are probably expecting XML, and not a SQL dataset with an XML column in it. You might care to take a look at these MSDN examples on how to skip the step above....

    http://msdn.microsoft.com/en-us/library/ms180838.aspx

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Hi Matt,

    Yes, that works. Thanks million!

    Chris

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

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