1

I am trying to create xml from sql server and I am almost done with my query. But, I have a problem that I couldnt figure it out. How can I add an attribute to root "ITEM", not "ITEMS"? My sql query is below...

SELECT  
            CARD_TYPE
            ,CODE
            ,NAME
            ,UNITSET_CODE
            ,AUXIL_CODE
            ,AUXIL_CODE2
            ,AUXIL_CODE3
            ,AUXIL_CODE4
            ,AUXIL_CODE5
            ,CYPHCODE
       FROM P_ITEMS
      WHERE HOSTGROUPID='7155d850-5882-43a0-b722-f6586bfffa61'
        AND TRANCODE ='ITEMS'
        AND PROCESSED ='NEW'
        FOR XML PATH('ITEM'),ROOT('ITEMS')
0

1 Answer 1

2

Try it like this

SELECT  
        'theAttributValue' AS [@MyAttribut]
        ,CARD_TYPE
        ,CODE
        ,NAME
        ,UNITSET_CODE
        ,AUXIL_CODE
        ,AUXIL_CODE2
        ,AUXIL_CODE3
        ,AUXIL_CODE4
        ,AUXIL_CODE5
        ,CYPHCODE
   FROM P_ITEMS
  WHERE HOSTGROUPID='7155d850-5882-43a0-b722-f6586bfffa61'
    AND TRANCODE ='ITEMS'
    AND PROCESSED ='NEW'
    FOR XML PATH('ITEM'),ROOT('ITEMS')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.