I have nearly accomplished what I need, but am missing one last thing. I have 2 tables being joined to create an XML output. I need elements of both tables to be used in the same SELECT statement, but am having trouble making that work. This code is what I have:
SELECT
1 as Tag,
0 as Parent,
RTRIM(dbo.DataItemInfo.DataItem) as [DataItem!1!name]
--RTRIM(dbo.DataItemInfo.DataItem) as [dbo.DataSchedule.DataItemValue!1!]
FROM
dbo.DataItemInfo
INNER JOIN
dbo.DataSchedule
ON dbo.DataSchedule.SignID = dbo.DataItemInfo.SignID
AND dbo.DataSchedule.SignID=@ParamSignID
AND dbo.DataSchedule.ScheduleID = dbo.DataItemInfo.ScheduleID
FOR XML EXPLICIT, ROOT('DataItems')
Where the commented out section is one of the things I tried. At the moment, it produces the output:
<DataItems>
<DataItem name="Test1" />
<DataItem name="Test2" />
<DataItem name="Test3" />
<DataItem name="Test4" />
<DataItem name="Test5" />
</DataItems>
But I want:
<DataItems>
<DataItem name="Test1">ValFromScheduleTableHere<DataItem/>
<DataItem name="Test2">ValFromScheduleTableHere<DataItem/>
<DataItem name="Test3">ValFromScheduleTableHere<DataItem/>
<DataItem name="Test4">ValFromScheduleTableHere<DataItem/>
<DataItem name="Test5">ValFromScheduleTableHere<DataItem/>
</DataItems>
I know how to populate the "ValFromScheduleTableHere" from the original table, but not from a second table. Thanks for the help.
FOR XML PATH? It's typically much easier to understand and get the results you want, compared toFOR XML EXPLICIT...EXPLICITand couldn't make any sense of it, as far as I remember I had to useFOR XML PATH(''), TYPEin the inner select to get the same results.