I am new to TSQL and require some help with a problem I'm having.
I have a stored procedure where I create a temporary table:
Create Table #TempSourceOutput(
SourceComment varchar(max) )
and I can successfully populate it using:
Insert Into #TempSourceOutput (SourceKey, SourceID, SourceComment)
Select @SourceKey, Cast(@SourceID as varchar), @SourceComment
however, I would like to get all the values from this table and list them (along with other variables) in a varchar, resulting in something like this:
Declare @TargetData varchar(max)
Set @TargetData = "Target Project Name"
Set @msg= 'Are you sure you wish to copy the following records to: ' + @TargetData + '?' +
'AA 12 Test Comment'
'AB 13 Another Test Comment'
'AC 14 And another one...'
(where lines above AA, AB, AC are the result set of #TempSourceOutput - ie. columns SourceKey + SourceID + SourceComment)
I would like to return it all as one complete varchar.
Is it at all possible, and if so, how.
Many thanks for your help in advance.