I thought that you just needed to separate two file names with a ;
but my syntax fails with an error of
Msg 102, Level 15, State 1, Line 251
Incorrect syntax near '@filename2'.
This is my full syntax, what do I need to do in order to attach both files to my email?
Declare @filename1 varchar(max), @filename2 varchar(max)
Set @filename1 = 'C:\Testfiles\Test1.csv'
Set @filename2 = 'C:\Testfiles\Test2.csv'
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'Mod',
@from_address = 'modis@modisglobal.com',
@recipients= 'rsmith@gmail.com',
@subject= 'Test Email',
@body = @body1,
@file_attachments = @filename1;@filename2;
Best Answer
The semi-colon is a statement terminator, and you haven't correctly escaped your attachments. In other words, you've done this:
According to the MSDN article on
sp_send_dbmail
:You need to do this:
If you want to programmatically add attachments, you would do something like this (notice how the second and third files begin with a semi-colon):