Home All Groups Group Topic Archive Search About

Incorrect syntax near '+'!

Author
2 Jul 2005 9:16 AM
Arpan
What's wrong with the following code?

EXEC xp_sendmail
    @recipients***@b.com',
    @copy_recipients***@c.com;*@d.com;*@e.com',
    @subject='SQL Server Report!',
    @message='Report generated on' + CAST(GETDATE() AS varchar(50)) + '!',
    @query='SELECT * FROM INFORMATION_SCHEMA.TABLES',
    @attach_results='TRUE',
    @width=250

The above, when executed, throws an error saying "Incorrect syntax near
'+' pointing to the @message statement. Where am I erring?

Thanks,

Arpan

Author
2 Jul 2005 9:35 AM
Steve Harclerode
I don't think you can use "+" in the call to a stored proc like you are
below. Try this:

DECLARE @msg VARCHAR(80)
SET @msg = 'Report generated on' + CAST(GETDATE() AS varchar(50)) + '!'

EXEC xp_sendmail
@recipients***@b.com',
@copy_recipients***@c.com;*@d.com;*@e.com',
@subject='SQL Server Report!',
@message= @msg,
@query='SELECT * FROM INFORMATION_SCHEMA.TABLES',
@attach_results='TRUE',
@width=250

- Steve

Show quote
"Arpan" <arpan***@hotmail.com> wrote in message
news:1120295790.949941.306740@g49g2000cwa.googlegroups.com...
> What's wrong with the following code?
>
> EXEC xp_sendmail
> @recipients***@b.com',
> @copy_recipients***@c.com;*@d.com;*@e.com',
> @subject='SQL Server Report!',
> @message='Report generated on' + CAST(GETDATE() AS varchar(50)) + '!',
> @query='SELECT * FROM INFORMATION_SCHEMA.TABLES',
> @attach_results='TRUE',
> @width=250
>
> The above, when executed, throws an error saying "Incorrect syntax near
> '+' pointing to the @message statement. Where am I erring?
>
> Thanks,
>
> Arpan
>
Author
4 Jul 2005 12:38 AM
Arpan
Thanks, Steve, for your help. Your suggestion is working fine. So can
it be ultimately concluded that "+" cannot be used to execute a stored
procedure?

Thanks once again,

Regards,

Arpan

AddThis Social Bookmark Button