xp_SendMail

  • Hi,

    I'm trying to send mail from sql 7.0 and am having problems making the query work. I want to be able to select a surname for the output as below

    EXEC xp_sendmail

    @Recipients = 'Scott Fisher',

    @dbuse = 'AdaptData',

    @Query = 'SELECT CustomerNo, Surname FROM tblCustomerData Where Surname = '

    GO

    What is the syntax for adding the where clause. ie I thought

    @Query = 'SELECT CustomerNo, Surname FROM tblCustomerData Where Surname = 'Fisher''

    But nope...

    Thanks in advance

    Scott

  • Since ' (single quote) is the text delimiter in SQL you have to double up or '' when qualifiying text inside. Try

    @Query = 'SELECT CustomerNo, Surname FROM tblCustomerData Where Surname = ''Fisher'''

    Should do the trick.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • Thanks very much...works perfectly

    Scott

  • You could also construct your query string in a separate variable, then just pass that to @query.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply