I have the following table:
CREATE TABLE [dbo].[MyTable](
[Day_ID] [nvarchar](50) NULL,
[SAS] [nvarchar](50) NULL,
[STAMP] [datetime] NULL DEFAULT (getdate())
)
which contains this data:
- '2017_12_06_01','Red'
- '2017_12_06_02','Yellow'
- '2017_12_06_03','Green'
- '2017_12_06_04','Blue'
I also have a SP which read all the data from MyTable
and send it in the body of an e-mail message.
SET NOCOUNT ON;
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'MyMailProfile'
,@recipients = 'me@account.com'
,@subject = 'This is the object'
,@body = 'This is the body:'
,@body_format = 'TEXT'
,@query = 'SET NOCOUNT ON select [Day_ID],[SAS] from MyTable SET NOCOUNT OFF'
,@attach_query_result_as_file = 0
,@query_result_separator = '|'
,@exclude_query_output = 1
,@query_result_no_padding = 0
,@query_result_header = 0
,@append_query_error=1
Everything works but my problem is that in the body the results appear like these:
2017_12_06_01 |Red
2017_12_06_02 |Yellow
2017_12_06_03 |Green
2017_12_06_04 |Blue
In other words SQL Server know that the columns could be 50 characters long so they fill the space that doesn't contain characters with spaces. This is very boring if you consider that happen also if you write numeric values into a column, for example, NUMERIC. I've tried with LTRIM and RTRIM but nothing changed.
I am using SQL Server 2005.