Avatar of metropia
metropia
Flag 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.
Microsoft SQL ServerSSRSSQL

Avatar of undefined
Last Comment
chaau

8/22/2022 - Mon
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.
metropia

ASKER
my bad

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

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Your help has saved me hundreds of hours of internet surfing.
fblack61