Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
andrewcw
Posting Yak Master
133 Posts |
Posted - 2015-03-22 : 23:12:29
|
This should be rather simple. To begin this Stored procedure I need to check 2 incoming parameters. If @mostRecentDate is not given ( assuming its NULL, I will then use GETDATE() to use today. However, if the @oldestWhenDate is null, I wont process the request. I have added print statements but I still cannot see what's wrong. Must be simple.Here's the SP sectionALTER PROCEDURE [dbo].[usp_PROCESS_DateRange] @oldestWhenDate smalldatetime = null, @mostRecentDate smalldatetime=nullAS BEGINdeclare @LNStartDate smalldatetimedeclare @LNEndDate smalldatetimePRINT 'FIRST CHECK @mostRecentDate for NULL'PRINT ' @mostRecentDate '+ coalesce(Convert(varchar(30), @mostRecentDate ),'@mostRecentDate is null') IF ( @mostRecentDate=null) BEGIN PRINT ' no end date. so GETDATE' set @mostRecentDate=GetDate() END SET @LNEndDate=@mostRecentDate PRINT 'assign end date is: ' + coalesce(Convert(varchar(15), @LNEndDate),' @LNEndDate is null') PRINT '2nd CHECK @oldestWhenDate NOT NULL' IF ( @oldestWhenDate !=null) BEGIN PRINT ' assign variable for start date' SET @LNStartDate= @oldestWhenDate END IF ( @LNStartDate=null) BEGIN PRINT ' error, no begin date given must exit' return ENDEND RETURNWhen I use the SSMS and bypass the option to do input parameters, I get this:FIRST CHECK @mostRecentDate for NULL@mostRecentDate @mostRecentDate is nullassign end date is: @LNEndDate is null2nd CHECK @oldestWhenDate NOT NULLI expected GETDATE to have been used.And if the values are not NULL, I'd like to know what they are.How do I use IF statements for these values? Thanks andrewcw |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2015-03-23 : 08:58:00
|
To check for nulls, writeIF ( @mostRecentDate is null) |
|
|
|
|
|
|
|