We help IT Professionals succeed at work.

SQL Syntax problem

I got a quick question that it not making sense to me ...

I run this
DECLARE @NextMailingDate as varchar(200)
DECLARE @MailingDate as datetime      

SELECT @MailingDate = MIN(MailingDate) --AS NextMailDate
      from tblMSDesignMailings WHERE (JobRFID IN(Select JobRFID From #tmpTable2)) AND (MailingDate > GetDate()) ;
      SET @NextMailingDate = 'Next mailing scheduled for: '       
 SELECT @NextMailingDate
RETURNS =  'Next mailing scheduled for: '
and the results are as you would think but when I try to concatenate a date to it, if the date is NULL the whole string goes away for some reason. For instance, if I run this it returns NULL

DECLARE @NextMailingDate as varchar(200)
DECLARE @MailingDate as datetime      

SELECT @MailingDate = MIN(MailingDate) --AS NextMailDate
from tblMSDesignMailings WHERE (JobRFID IN(Select JobRFID From #tmpTable2)) AND (MailingDate > GetDate()) ;
SET @NextMailingDate = 'Next mailing scheduled for: '
SET @NextMailingDate = @NextMailingDate + cast(@MailingDate as varchar(10))+ '<br /><br />' This line seems to ruin it for some reason and I cant figure out why???

 SELECT @NextMailingDate
Returns = NULL

Thanks for any help
Comment
Watch Question

You should use ISNULL function...

ex:
declare @MailingDate Varchar(25)
DECLARE @NextMailingDate as varchar(200)
SET @NextMailingDate = 'Next mailing scheduled for: '
select  @MailingDate = crdate from sysobjects where crdate > getdate()+1000
select  @MailingDate
SET @NextMailingDate = @NextMailingDate + cast(isnull(@MailingDate,'Enter the value/test needed') as varchar(10))+ '<br /><br />'
select  @NextMailingDate

Author

Commented:
I was just abuot to reply to my own post that I used the ISNULL function...But you answered it so the points are yours...Thanks for the help!

Author

Commented:
thanks