I've got a problem with my T-SQL query. There is one table where I want to count everything but when canceldate
(it's a column with dates) is null then @currentdate
(that is a parameter) should be between startdate
and enddate
. Else @currentdate
should be between startdate
and canceldate
.
Here is my code but still i don't know how should i build it.
declare @currentdate as date
select count(*) from Table
where
case when Canceldate is null then
@currentdate between startdate and enddate
else
@currentdate between startdate and canceldate
group by personalnum