April 29, 2015 at 1:57 am
i am using below condition for sending mail, but i want add the condition for not to send mail "IF (@mSql2 IS NULL )"
can someone provide the code part for that .
-- Condition for Send Mail
SET @mSql2 = N'select * from Tablename';
IF (@mSql2 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
April 29, 2015 at 2:00 am
Right now, how your code is structured, there won't be an email sent if (@mSql2 IS NULL ). So what else do you want to accomplish?
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
April 29, 2015 at 2:08 am
it sending blank email if the table is empty.
i dont want to receive mail if the the table is empty.
April 29, 2015 at 2:11 am
charipg (4/29/2015)
it sending blank email if the table is empty.i dont want to receive mail if the the table is empty.
Ah, I see.
You are currently checking if the string "select * from Tablename" is NULL or not. This statement does not get executed.
Of course it's never NULL.
Try this:
IF EXISTS (SELECT 1 FROM TableName)
BEGIN
...
END
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
April 29, 2015 at 3:05 am
its not working.still the blank mail queued.
April 29, 2015 at 3:34 am
thank you Koen Verbeeck !! it is working now.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply