March 10, 2019 at 11:47 pm
In subject line of email I want @Subject to return "'Submission at 10/03/2019 22:46:34".
Concatenating with + and quotes isn't working. How is it done?
DECLARE @Recipients varchar(max) = 'polkadot@email.com',
@Subject varchar(max) = 'Submission at ',
@Body varchar(max) = null,
@ReportDate varchar(50) = FORMAT(GETDATE() , 'dd/MM/yyyy HH:mm:ss'),
@emailbody varchar(max) = 'The attached excel contains stuff';
EXECUTE msdb.dbo.sp_send_dbmail
@Recipients = @Recipients,
@Subject = @Subject + ' ' + FORMAT(GETDATE() , 'dd/MM/yyyy HH:mm:ss'),
@Body = @emailbody,
@file_attachments = @FileShare2;
--Quote me
March 11, 2019 at 12:00 am
Odd. When I tried it without any of the SendMail part, it worked:DECLARE @Recipients varchar(max) = 'polkadot@email.com',
@Subject varchar(max) = 'Submission at ',
@Body varchar(max) = null,
@ReportDate varchar(50) = FORMAT(GETDATE() , 'dd/MM/yyyy HH:mm:ss'),
@emailbody varchar(max) = 'The attached excel contains stuff';
SET @Subject = @Subject+ ' ' + FORMAT(GETDATE() , 'dd/MM/yyyy HH:mm:ss');
PRINT @Subject;
Result:
Submission at 11/03/2019 00:58:21
March 11, 2019 at 12:19 am
works for me. Thank you peitlinden 🙂
--Quote me
March 11, 2019 at 6:20 am
I'd recommend that you get out of the habit/crutch of using FORMAT. Yeah... it's nice and easy but it's a bad habit until they fix the major performance issues it has. Justifying it's use for a one-off low-row-count is a poor justification for not practicing faster methods and just leads to a "Death of a Thousand Cuts" in the database over time.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 11, 2019 at 6:31 am
polkadot - Sunday, March 10, 2019 11:47 PMIn subject line of email I want @Subject to return "'Submission at 10/03/2019 22:46:34".
Concatenating with + and quotes isn't working. How is it done?
DECLARE @Recipients varchar(max) = 'polkadot@email.com',
@Subject varchar(max) = 'Submission at ',
@Body varchar(max) = null,
@ReportDate varchar(50) = FORMAT(GETDATE() , 'dd/MM/yyyy HH:mm:ss'),
@emailbody varchar(max) = 'The attached excel contains stuff';
EXECUTE msdb.dbo.sp_send_dbmail
@Recipients = @Recipients,
@Subject = @Subject + ' ' + FORMAT(GETDATE() , 'dd/MM/yyyy HH:mm:ss'),
@Body = @emailbody,
@file_attachments = @FileShare2;
The issue is that you're trying to do a calculation for a parameter and pass the parameter at the same time. You have to do the calculation first as a variable and then use the variable as a parameter. It's just the way procs work.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply