Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Building a varchar(max) from multi query results
Message
From
16/07/2012 20:53:59
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Building a varchar(max) from multi query results
Environment versions
SQL Server:
SQL Server 2008
Miscellaneous
Thread ID:
01548693
Message ID:
01548693
Views:
66
Really need help with this one.

As I process records in my SP I am building a cursor representing conditions that will go into a VARCHAR(MAX) column in a batch table to show the results of the processing

I am getting a syntax error on the SELECT I am trying to append to my @text variable.

Obviously what I am trying to do is build a varchar(max) including CRLFs, inserting category headings and then info from all rows in my @textbody that fix that category.

Is there a problem using CHAR(13)+CHAR(10) pairs for CRLF ? This varchar(max) column is going to be used as the body of an email.

If it is just a syntax tweak would appreciate guidance or if there is some other slick solution ...
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 = @batchid
Naomi, I'll owe you a dinner. <g>

UPDATE: Naomi I'll still owe you the dinner but I think I figured out I need to use SELECT instead of SET as in
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, symbol
Yeah?


Charles Hankey

Though a good deal is too strange to be believed, nothing is too strange to have happened.
- Thomas Hardy

Half the harm that is done in this world is due to people who want to feel important. They don't mean to do harm-- but the harm does not interest them. Or they do not see it, or they justify it because they are absorbed in the endless struggle to think well of themselves.

-- T. S. Eliot
Democracy is two wolves and a sheep voting on what to have for lunch.
Liberty is a well-armed sheep contesting the vote.
- Ben Franklin

Pardon him, Theodotus. He is a barbarian, and thinks that the customs of his tribe and island are the laws of nature.
Next
Reply
Map
View

Click here to load this message in the networking platform