I'm writing a select statement for a large database whereby I'm copying from one system to another.
Both use the same column names as the element names.
For example
SELECT
1 'job/queue',
0 'job/branch',
'create-apm' 'parameters/yzt/char20.1',
c.Name 'apmdata/prospect/p.cm/',
c.Addr1 'apmdata/prospect/p.cm/'
FROM
dbo.ic_brpolicy AS p
INNER JOIN
dbo.ic_yyclient AS c ON c.B@ = p.B@
AND c.Ref@ = p.Ref@
WHERE
p.PolRef@ = 'ANCX38PC01'
FOR XML PATH('xmlexecute'), TYPE ;
You can see 'Name' and 'Addr1' both of these are the same names the elements need to be i.e.
c.Name 'apmdata/prospect/p.cm/Name'
c.Addr1 'apmdata/prospect/p.cm/Addr1'
Is there anyway I can get the column title as the output element without using dynamic SQL?
If dynamic SQL is the only way to do it then that's the route I'll have to go down as it'll save lots of time but still isn't ideal from a best practice point of view.
Cheers.