DECLARE @textbody TABLE ( symbol char(6), eff_date datetime, effdate char(8), cntry_code char(2), ntype char(10), condition char(50), eventid char(10), fcid char(10), fctid char(10), bsid char(10) ) --- @textbody gets properly filled declare @text varchar(max) SET @text = 'SPI FEED FILE '+ @csvfile + ' Processed '+@procdatetime+char(13)+char(10) +char(13)+char(10) +'New Corporate Actions' + char(13)+char(10) SET @text = @text + SELECT cntry_code + ' ' + effdate + ' ' + symbol + ' ' +fcid + ' ' + condition + char(13) + char(10) from @textbody where ntype = 'New' order by cntry_code, eff_date desc, symbol SET @text = @text + char(13)+char(10) +'Updated Corporate Actions ' + char(13)+char(10)+char(13)+char(10) SET @text = @text + SELECT cntry_code + ' ' + effdate + ' ' + symbol + ' ' +fcid + ' ' + condition + char(13) + char(10) from @textbody where ntype = 'Update' order by cntry_code, eff_date desc, symbol SET @text = @text + char(13)+char(10) +'DJI Created Corporate Actions Updated ' + char(13)+char(10)+char(13)+char(10) SET @text = @text + SELECT cntry_code + ' ' + effdate + ' ' + symbol + ' ' +fcid + ' ' + condition + char(13) + char(10) from @textbody where ntype = 'UpdateDJI' order by cntry_code, eff_date desc, symbol .... --- and finally Update FCA_Backfeed_batch SET Notification_email_body = @text, NumberOfRows = @stgcount where fca_backfeed_batch_id = @batchidNaomi, I'll owe you a dinner. <g>
SELECT @text = @text + char(13)+char(10) +'Updated Corporate Actions ' + char(13)+char(10)+char(13)+char(10) SELECT @text = @text + cntry_code + ' ' + effdate + ' ' + symbol + ' ' +fcid + ' ' + condition + char(13) + char(10) from @textbody where ntype = 'Update' order by cntry_code, eff_date desc, symbolYeah?