I am passing into a stored procedure two variables @begindate
& @enddate
. I need to check firsttabletocheck
and get a count of where csdate
is between @begindate
and @enddate
.
I then need to check and see if any of the dates between @begindate
& @enddate Not Exists
in firsttabletocheck
I need to query secondtabletocheck
to get a count from that.
I can write my code to do 1 table, but not quiet sure how to write it to do the other. For example this is my current syntax that only checks 1 table, how can I add in the check for the second table?
Declare @d1 datetime, @d2 datetime, @numreturned int
Set @d1 = '01/01/2015'
Set @d2 = '01/12/2015'
Set @numreturned = 0
Set @numreturned = (Select COUNT(*)
FROM firsttabletocheck
where csdate BETWEEN @begindate and @enddate)
How can I add my not exist here to check if the date does not exist in the above table then check this table?
For example let's say that all dates in the date range exist in firsttabletocheck
EXCEPT 01/11/2015 then I need to query the second table to check if 01/11/2015 exists in that table.