Hi there. I need to produce output in a specific XML format. The normal FOR XML AUTO, RAW etc don't produce the output I need and would appreciate some guidance on using the FOR XML EXPLICIT option.The format of the output is as follows:<CurrencyRateHistoricInsert> -- This is a section header <BaseCurrency> xxx <BaseCurrency> -- This is a value in a table and only a single entry <CurrencyRatesInstanceList> --Sub-Section Header <CurrencyRatesInstance> --Sub-Sub-Section Header <Date> xxxxxxyyyyyy <Date> --value in table <CurrencyList> --Sub Section Header <CurrencyRate> --Sub-Sub-Section Header <Name> xxx <Name> -- Value in table <Rate> yyy >Rate> -- Value in table ... ... ...I can get values returned into sections however I cant seem to be able to place section headers....What am I doing wrong?SELECT 1 as TAG, NULL as Parent, NULL as [CurrencyRateHistoricInsert!1], 'GBP' as [CurrencyRateHistoricInsert!1!BaseCurrency!element], 2 as [CurrencyRateHistoricInsert!1!CurrencyRatesInstanceList!ELEMENT], NULL as [CurrencyList!2!Date!ELEMENT], NULL as [CurrencyList!2!Name!ELEMENT], NULL as [CurrencyList!2!Rate!ELEMENT]from exchange_Rate_Historywhere effective_date >'20100912'UNION ALLSELECT 2 as TAG, 1 as Parent, Null, Null, NULL, effective_date, Currency_Key, exchange_ratefrom exchange_Rate_Historywhere effective_date >'20100912'for XML explicit, ROOT('MYXML')
I'm getting the following outpur received....<MYXML> <CurrencyRateHistoricInsert> <BaseCurrency>GBP</BaseCurrency> <CurrencyRatesInstanceList>2</CurrencyRatesInstanceList> </CurrencyRateHistoricInsert> <CurrencyRateHistoricInsert> <BaseCurrency>GBP</BaseCurrency> <CurrencyRatesInstanceList>2</CurrencyRatesInstanceList>...........<CurrencyList> <Date>2010-09-13T00:00:00</Date> <Name>ZAR</Name> <Rate>8.787327</Rate> </CurrencyList> <CurrencyList> <Date>2010-09-13T00:00:00</Date> <Name>ZAR</Name> <Rate>10.493266</Rate> </CurrencyList> <CurrencyList> <Date>2010-09-13T00:00:00</Date> <Name>ZMK</Name> <Rate>704.780103</Rate> </CurrencyList>So its generating the outoput but its more of a formatting issue I think.