question

siera_gld avatar image
siera_gld asked

Use Expression in sp send_db_mail attachment

I have a file i want to attach in a send db mail task but the file name is a variable. When I build the whole path and filename as a sql expression - it does not resolve the expression as the filename. Here is my expression - @file_attachments = \\\\Export'+REPLACE(CONVERT(char(8), getdate(), 10), '-', '')+'zip' It fails around the "+" Error message Msg 102, Level 15, State 1, Line 5 Incorrect syntax near '+'.
dbmailfilespattachment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Magnus Ahlkvist avatar image
Magnus Ahlkvist answered
If that is the exact statement from your code, you are missing the leading quote in the expression. Should be: @file_attachments = '\\\\Export'+REPLACE(CONVERT(char(8), getdate(), 10), '-', '')+'zip' Apart from that I can't find any problems with the statement.
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

siera_gld avatar image
siera_gld answered
Magnus - In my post I accidentally ommitted but in the t-sql I have it as you mention - it looks right but abends on the '+'
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.