Created
April 24, 2016 12:57
-
-
Save ysinc88/db96fd0f6280a6abef2b58bfd9aacec2 to your computer and use it in GitHub Desktop.
SQL - combining case between and where
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION ys_payments (@ent int,@year int,@q int) | |
RETURNS TABLE | |
AS | |
RETURN | |
... | |
where year(reportingPeriod) = @year | |
and | |
case | |
when @q = 1 then month(reportingPeriod) between @q and @q + 2 | |
when @q = 2 then month(reportingPeriod) between @q + 2 and @q + 4 | |
when @q = 3 then month(reportingPeriod) between @q + 4 and @q + 6 | |
else month(reportingPeriod) between @q + 6 and @q + 10 | |
end | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment