FOLLOW US

Tuesday, January 10, 2012

SSIS Carriage Return in MesageSource 'Send Mail Task'

Yesterday I faced a layout problem within the 'Send Mail Task' in BIDS. The task had to report status information in a mail in a readable manner. I composed the context of the mail in a variable wich is set bij an 'Execute SQL Task' in a 'Foreach Loop Container' which fills the variable by means of a Result Set.

Initially I composed the status information one after another and it became one big lumb of text which was not readable. So I had to insert 'Carriage Returns' in order to get new status information on a new line.

By adding CHAR(13) to a text in a SQL statement you can add 'Carriage Returns' to a text so you can make it more readable.

Example:
SELECT 'This is a example text.' + CHAR(13) + 'And this must be on a new line!' + CHAR(13) + 'And this must be on another new line!'

If you put this in a variable and put the content of this variable into the MessageSource property of the 'Send Mail Task' through a exception you will get the following result:

This is a example text.
And this must be on a new line!
And this must be on another new line!

Hope this helps!

No comments:

Post a Comment