I am trying to use the STUFF functionality in SQL Server 2016 to select DATE information and return it to a table. Occasionally there are multiple dates to return. I have already used STUFF to get other data I need.
Email = STUFF((SELECT ', ' + [Value]
FROM EmailTable
WHERE ID = r.ID AND EmailType = 1
FOR XML PATH(''),TYPE).value('(./text())[1]','NVARCHAR(MAX)'),1,2,'')
This can return multiple emails where applicable and works fine. Now the problem is I want to do the same but with a DATE.
Date = STUFF((SELECT ', ' + DateValue
FROM DateTable
WHERE ID = r.ID
FOR XML PATH(''),TYPE).value('(./text())[1]','DATE'),1,2,'')
The above code snippets are just examples, the table and variable names are different in reality, but they should convey what I'm getting at.
The error for the last code snippet is that it will not work because of the '+' symbol. If I take the comma and plus out I can get it to return DATEs but they are wrapped in XML tags.
Also it has to return a DATE value, it can not be converted to NVARCHAR.
I'm not sure if what I am after is doable but I thought I would ask.
If any more information is needed please ask.