Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Send Mail Task Email Format SSIS 2012

$
0
0

I have a 2012 sql server stored procedure that concatenates rows of data into a single record. Each record is seperated by the litteral string, 'crlf'. When the data is return to my 2012 ssis package, the return data is set to a string variable named 'emailMessage'. The variable is examined in an expression, and all instances of 'crlf' are replaced with line breaks '\n'. This is done so that each record will be contained on a seperate line in the email message.

The problem that I have is that the proc performs some formatting to make sure spacing of the data is correct, but the results render differently between email clients like MS Outlook. If I take the results I get in MS Outlook, and put them in notepad, everything lines up correctly in notepad. In Outlook, the 'columns' of data do not line up correctly.

Is there a way, with the Send Mail Task, that I can control whether or not a message is sent as text or html?

NOTE: I'm only returning records through the Send Mail Task this way because the client will not allow for script tasks, nor the use of the db_sendmail system proc.

the following is my procedure:

--******************************

CREATE PROCEDURE dbo.ReturnNames

@ConcatRecordLocal varchar(8000) OUTPUT

as

set nocount on

--Need to know what the max length of every field, and column name:
declare
 @MaxLenFirstName int
 ,@FirstNameColumnNameLen int
 ,@MaxLenMiddleName int
 ,@MiddleNameColumnNameLen int
 ,@MaxLenLastName int
 ,@LastNameColumnNameLen int


--Set the length of the names of the columns:
set @FirstNameColumnNameLen = 9
set @MiddleNameColumnNameLen = 10
set @LastNameColumnNameLen = 8

--get the max length of the column data:
select
 @MaxLenFirstName = max(len(firstName))
 ,@MaxLenMiddleName = max(len(middleName))
 ,@MaxLenLastName = max(len(lastName))
from
dbo.Names


--if the name of the column is longer than any of the data in it, use the length of the column name:
if @FirstNameColumnNameLen > @MaxLenFirstName
 begin
  select @MaxLenFirstName = @FirstNameColumnNameLen
 end

if @MiddleNameColumnNameLen > @MaxLenMiddleName
 begin
  select @MaxLenMiddleName = @MiddleNameColumnNameLen
 end

if @LastNameColumnNameLen > @MaxLenLastName
 begin
  select @MaxLenLastName = @LastNameColumnNameLen
 end

--use char to make string timming easier:
declare @ErrorTable TABLE
( NameID int identity(1,1) not null
 ,firstname char(25) not null
 ,middleName char(25) not null
 ,lastname char(25) not null
)

--variables to assist with building a string of records:
declare
 @RecordCount int
 ,@Counter int
 ,@ConcatRecord varchar(7000)
 ,@CRLFIndicator char(4)

set @Counter = 0
set @ConcatRecord = ''
set @CRLFIndicator = 'crlf' -- will use this in SSIS to find and replace with a line break.

insert @ErrorTable
(firstname, middlename, lastName)
select firstname, middlename, lastname from dbo.names

--this drives the number of times the 'while' loop executes:
select @recordCount = count(*) from @ErrorTable

--initialize @ConcatRecord with field names:
select @ConcatRecord = 'firstName ' + 'middleName ' + 'lastname ' + @CRLFIndicator


--build the one record of concatenated rows of data:
while (@Counter<= @recordCount)
 begin

  select @ConcatRecord = @ConcatRecord + LEFT (firstname, (@MaxLenFirstName + 1)) + LEFT(middleName, (@MaxLenMiddleName + 1)) + LEFT(lastName, (@MaxLenLastName + 1))  from @ErrorTable where Nameid = @Counter
  select @ConcatRecord = @ConcatRecord + @CRLFIndicator

  from dbo.names where NameID = @Counter

 set @counter = @counter + 1

 end

--return the result:
select @ConcatRecordLocal = @ConcatRecord

--***********************************************

Thank you for your help.

cdun2



Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>