Announcement

Collapse
No announcement yet.

Condition for Not to Send Mail

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Condition for Not to Send Mail

    Hi,

    I am using below condition for sending mail from SQL Server, but i want add the condition for not to send mail "IF (@A1SQL IS NULL )"

    can someone provide the code part for that?

    -- Condition for Send Mail

    [HTML]SET @A1SQL = N'select * from Tablename';

    IF (@A1SQL IS NOT NULL )
    BEGIN

    SET @tableHTML =

    N'<H1> details</H1>' +

    N'<table border="1">' +
    N'<tr><th>createdate</th>' +
    N'<th>dbname</th>' +

    CAST ( ( SELECT "td/@align" = 'right', td = createdate, '',
    "td/@align" = 'right', td = dbname, ''


    FROM TableName

    FOR XML PATH('tr'), TYPE

    ) AS NVARCHAR(MAX) ) +

    N'</table>' ;

    EXEC MSDB.DBO.SP_SEND_DBMAIL
    @profile_name='xxxx',
    @recipients='xxxxx',
    @subject =' details ' ,
    @body = @tableHTML,
    @body_format ='HTML'
    end[/HTML]

    thanks.

    [MOD EDIT - hyperlink to commercial (spam) site removed and warning issued. Next time WILL be a ban]
    [MOD EDIT 2 - "Next time" was in the user profile.... bye, bye ]

    Last edited by Ossian; 15th May 2015, 09:42.
Working...
X