Home Forums SQL Server 2008 T-SQL (SS2K8) Select All Records from Temporary Table and Assign to VARCHAR? RE: Select All Records from Temporary Table and Assign to VARCHAR?

  • Thank you both kapil_kk & Luis Cazares,

    I'm sorry I have been unexpectedly offline for a few days so apologies for the late reply.

    I managed in the end and it wasn't too difficult either.

    Here is what I did:

    I populated the table like so:

    --Concatenate source data values and insert into temp table, seperated by a $ sign

    Insert Into #TempSourceOutput (All_Source_Data)

    Select @SourceKey + ' [' + Cast(@SourceID as varchar) +'] '+ @SourceComment + '$'

    Then I got each row from temp table #TempSourceOutput and placed it in one single row of data for use in message later

    Declare @Txt1 varchar(MAX)

    Declare @AllSourceData varchar (max)

    Set @Txt1=''

    Select @Txt1 = @Txt1 + All_Source_Data

    From #TempSourceOutput

    Select @AllSourceData = LEFT(@Txt1,LEN(@Txt1)-1)

    Then I used the @AllSourceData variable in my message:

    Set @msg= 'Are you sure you wish to copy ' + CAST(@NumberOfTransfers as varchar) + ' Objects to ' + @TargetKey + ' [' +

    CAST(@TargetID as varchar) + '] ' + @TargetComment + '?' + CHAR(10)+CHAR(13) + Replace(@AllSourceData,'$',+

    CHAR(10)+CHAR(13))

    I'm sure it's not the most sophisticated of solutions, but it works for me.

    Many thanks for your help.

    Winnie