I'm having challenges understanding the @query_result_width parameter of sp_send_dbmail stored procedure. I would like the script to send an Excel csv attachment. My script is as follows:
--Put subject line in variable to make dynamic:
declare @Subject as varchar(100)
set @Subject = 'My file for ' + convert(varchar(12), getdate(), 101)
@body='Here''s the file...',
Some of the columns are returning with a lot of extra spaces after the data. I've tried using the @query_result_width parameter with various amounts, but it isn't removing the extra spaces. The stored procedure is calling a query similar to this:
select distinct ID,
NAME = replace(replace(company_name, ',', '","'),'"', '""'), --format commas & quotes differently.
ADDRESS = replace(replace(address_1, ',', '","'),'"', '""'), --format commas & quotes differently.
left(postal_code,5) as ZIP
from customer (nolock)
The extra spaces aren't showing up for the ID or ZIP columns. It seems to only show for the NAME & ADDRESS columns that are using the replace option. I've tried taking out the replace option out & it still puts the extra spaces in. I've tried rtrim on the columns & no go.
Anyone have any ideas on what I'm doing wrong? :crazy: