xp_sendmail

  • I have a query that works on its own, however when I put

    it into xp_sendmail it fails. It appears that the "set"

    command does not work. Here is the query. Any suggestions?

    Can you use variables within xp_sendmail @query section?

    EXEC master.dbo.xp_sendmail

    @recipients = 'Richard Peoples',

    @subject = 'The following Budget Checked items need

    attention.',

    @query ='DECLARE @A1 CHAR (20)

    DECLARE @A2 CHAR (2)

    SET @A1 = 'Yvette Palomo'

    SET @A2 = 'N'

    IF (select COUNT (*)

    from FSPROD75.dbo.PS_C_JRNLLN_BUDCHK

    where RETURN_TO_ANALYST = @A1 AND

    BUDGET_CHECK_CLEAR= @A2) > 0

    begin

    select A.JOURNAL_ID, A.PROJECT_ID, A.ACCOUNT,

    B.XLATLONGNAME from FSPROD75.dbo.PS_C_JRNLLN_BUDCHK A

    INNER JOIN FSPROD75.dbo.XLATTABLE B ON A.BCM_LINE_STATUS =

    B.FIELDVALUE

    where (((A.RETURN_TO_ANALYST)= @A1) AND

    ((A.BUDGET_CHECK_CLEAR)=@A2)) AND (B.FIELDNAME

    = "BCM_LINE_STATUS")

    end'

  • If you embed the query you need to add more quotes as in

    @query ='DECLARE @A1 CHAR (20)

    DECLARE @A2 CHAR (2)

    SET @A1 = ''Yvette Palomo''

    SET @A2 = ''N''

    IF (select COUNT (*)

    from FSPROD75.dbo.PS_C_JRNLLN_BUDCHK

    where RETURN_TO_ANALYST = @A1 AND

    BUDGET_CHECK_CLEAR= @A2) > 0

    begin

    select A.JOURNAL_ID, A.PROJECT_ID, A.ACCOUNT,

    B.XLATLONGNAME from FSPROD75.dbo.PS_C_JRNLLN_BUDCHK A

    INNER JOIN FSPROD75.dbo.XLATTABLE B ON A.BCM_LINE_STATUS =

    B.FIELDVALUE

    where (((A.RETURN_TO_ANALYST)= @A1) AND

    ((A.BUDGET_CHECK_CLEAR)=@A2)) AND (B.FIELDNAME

    = "BCM_LINE_STATUS")

    end'

    Far away is close at hand in the images of elsewhere.
    Anon.

Viewing 2 posts - 1 through 1 (of 1 total)

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