Link to home
Start Free TrialLog in
Avatar of metropia
metropiaFlag for United States of America

asked on

calculate date

I am working on a case statement, but I am unsure I am getting the logic from correct from the pseudo code. I was wondering if someone can give me a hand and let me know if my case seems to be doing what expected based on the words.

That is:

ContractOpenStartDate = Equal to TODAY if in the middle of contract OR if contract has not started yet OR NULL if Contract is closed

CASE 
  WHEN [sbo_wcnd].[ContractStart] <= @Today AND [sbo_wcnd].[ContractEnd] >= @Today 
    THEN @Today
  WHEN [sbo_wcnd].[ContractStart] > @Today
    THEN [sbo_wcnd].[ContractStart]
  WHEN [sbo_wcnd].[ContractEnd] < @Today
    THEN NULL
END	AS ContractOpenStartDate

Open in new window


And also...
ContractOpenEndDate = ALWAYS EndDate or NULL if contract is closed.
CASE 
  WHEN [sbo_wcnd].[ContractStart] <= @Today AND [sbo_wcnd].[ContractEnd] >= @Today 
    THEN @Today
  WHEN [sbo_wcnd].[ContractStart] > @Today 
    THEN [sbo_wcnd].[ContractStart]
  WHEN [sbo_wcnd].[ContractEnd] < @Today 
    THEN NULL 
END	AS ContractOpenStartDate

Open in new window

A contract is closed if its end date is in the past.

Thank you very much for your help.
Avatar of Gottler
Gottler

What you are trying to do here is Correct as per the statements you have given.

The only thing I'm confused is you have placed the same code twice.
Avatar of metropia

ASKER

my bad

                  ,      CASE
                              WHEN @Today < [sbo_wcnd].[ContractEnd]
                                    THEN [sbo_wcnd].[ContractEnd]
                              ELSE NULL
                        END      AS [ContractOpenEndDate]
SOLUTION
Avatar of Gottler
Gottler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of PortletPaul
PortletPaul
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial