SSIS SQL Task: In case of empty result set return some default value

DECLARE @ReportDate DATE=’01 JAN 1900′;
DECLARE @isProcessed BIT=1;
–in the following select query it does not return result set it just assign value to a variable.
SELECT @ReportDate=ReportDate, @isProcessed=IsDateProcessed
FROM ETL.ReportDateForProcessing
WHERE (ReportDateTag = ‘RiskScoreReportDate’) AND (IsDateProcessed = 0)
SELECT @ReportDate AS ReportDate, @isProcessed AS isProcessed

–IF @@ROWCOUNT<=0
–BEGIN

— PRINT ‘SORRY NO RESULTS TO DISPLAY’
— SET @ReportDate=’01 JAN 1900′
— SET @isProcessed=1
— PRINT @ReportDate
— PRINT @isProcessed
— SELECT @ReportDate AS ReportDate, @isProcessed AS isProcessed
–END

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s