x

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 = 
 \\<sharename>\<Directory>\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 '+'.

more ▼

asked Jul 29, 2011 at 11:13 PM in Default

avatar image

siera_gld
1k 82 88 93

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

If that is the exact statement from your code, you are missing the leading quote in the expression.

Should be:

 @file_attachments = 
   '\\<share>\<Dir>\Export'+REPLACE(CONVERT(char(8), getdate(), 10), '-', '')+'zip'
 

Apart from that I can't find any problems with the statement.

more ▼

answered Jul 30, 2011 at 12:28 AM

avatar image

Magnus Ahlkvist
22k 20 41 42

(comments are locked)
10|1200 characters needed characters left

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 '+'

more ▼

answered Jul 30, 2011 at 01:07 AM

avatar image

siera_gld
1k 82 88 93

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x35
x25
x9
x7

asked: Jul 29, 2011 at 11:13 PM

Seen: 1644 times

Last Updated: Jul 29, 2011 at 11:13 PM

Copyright 2017 Redgate Software. Privacy Policy