SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


xp_sendmail not sending @message text


xp_sendmail not sending @message text

Author
Message
John Waclawski
John Waclawski
SSC Veteran
SSC Veteran (252 reputation)SSC Veteran (252 reputation)SSC Veteran (252 reputation)SSC Veteran (252 reputation)SSC Veteran (252 reputation)SSC Veteran (252 reputation)SSC Veteran (252 reputation)SSC Veteran (252 reputation)

Group: General Forum Members
Points: 252 Visits: 418
I just figured out what my issue was. And as usual, it was something I was doing wrong. Albeit it's odd it works this way.

I was assigning several values to a @BodyText variable. Building a body message really. Then sending that @BodyText to the @Body for the sql server email.

The kicker here is that if any of the values are null, or blank (??), it nulls out the whole @BodyText variable & sends nothing at all. You'd think, logically, that if a value was blank or null, it would put that in that section & just send a blank value.

Here's my example:


Set @BodyText = 'Mirroring Status Alert!!!' + CHAR(13) + CHAR(13) +
'Date: ' + @DateTime + CHAR(13) +
'Server: ' + @@ServerName + CHAR(13) +
'Database: ' + UPPER(@DatabaseName) + CHAR(13) +
'Mirror Status: ' + CAST(@MirrorStatus AS VARCHAR(1)) + ' - ' + @MirrorStatusDescription + CHAR(13) + 'Unsent Log size: ' + @UnsentLogStatus



So if @MirrorStatusDescription or @UnsentLogStatus somehow ended up blank, the whole @BodyText was blank. That's just plain silly.

Anyways...I fixed it. I'm not sure why others were experiencing it unfortunately.

======================================================
John
SQL Server 200x Newb and proud of it! :-D
======================================================
zulmanclock
zulmanclock
Old Hand
Old Hand (350 reputation)Old Hand (350 reputation)Old Hand (350 reputation)Old Hand (350 reputation)Old Hand (350 reputation)Old Hand (350 reputation)Old Hand (350 reputation)Old Hand (350 reputation)

Group: General Forum Members
Points: 350 Visits: 472
To avoid this you can use:
SET CONCAT_NULL_YIELDS_NULL OFF

This will prevent a field where the value is NULL from making the entire result NULL as well.
John Waclawski
John Waclawski
SSC Veteran
SSC Veteran (252 reputation)SSC Veteran (252 reputation)SSC Veteran (252 reputation)SSC Veteran (252 reputation)SSC Veteran (252 reputation)SSC Veteran (252 reputation)SSC Veteran (252 reputation)SSC Veteran (252 reputation)

Group: General Forum Members
Points: 252 Visits: 418
zulmanclock (3/11/2013)
To avoid this you can use:
SET CONCAT_NULL_YIELDS_NULL OFF

This will prevent a field where the value is NULL from making the entire result NULL as well.



Ahhhh....That did the trick!! Thank you, very much!!!

======================================================
John
SQL Server 200x Newb and proud of it! :-D
======================================================
zulmanclock
zulmanclock
Old Hand
Old Hand (350 reputation)Old Hand (350 reputation)Old Hand (350 reputation)Old Hand (350 reputation)Old Hand (350 reputation)Old Hand (350 reputation)Old Hand (350 reputation)Old Hand (350 reputation)

Group: General Forum Members
Points: 350 Visits: 472
No problem at all.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search