Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combining to criterias into one Case Statement

Status
Not open for further replies.
Mar 20, 2009
102
US
I have the below statements:

SET @QtrClose = getdate()

SELECT @QtrClose = CloseDT from prtaxperiodclose where TaxPeriodID = @Qtr and TaxPeriodYear = @Year

What I need to accomplish by combining the 2 is:

When CloseDT is null set it = getdate(), otherwise -
SELECT @QtrClose = CloseDT from prtaxperiodclose where TaxPeriodID = @Qtr and TaxPeriodYear = @Year

How can I combine the 2 to make it work. The issue I am having is when the closedt hasn't been entered it is not pulling back any data.
 
Code:
SELECT @QtrClose = CASE WHEN CloseDT IS NULL
                             THEN GETDATE()
                        ELSE CloseDT END
       FROM prtaxperiodclose
WHERE TaxPeriodID   = @Qtr AND
      TaxPeriodYear = @Year

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Or
Code:
SELECT @QtrClose = COALESCE(CloseDT,GETDATE())
       FROM prtaxperiodclose
WHERE TaxPeriodID   = @Qtr AND
      TaxPeriodYear = @Year
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top