Skip to content

Instantly share code, notes, and snippets.

@ysinc88
Created April 24, 2016 12:57
Show Gist options
  • Save ysinc88/db96fd0f6280a6abef2b58bfd9aacec2 to your computer and use it in GitHub Desktop.
Save ysinc88/db96fd0f6280a6abef2b58bfd9aacec2 to your computer and use it in GitHub Desktop.
SQL - combining case between and where
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