# 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``````

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``````
A contract is closed if its end date is in the past.

Thank you very much for your help.
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.

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

membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
PortletPaul

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

membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.