Skip to content

Instantly share code, notes, and snippets.

@orangexception
Created November 12, 2012 16:12
Show Gist options
  • Save orangexception/4060217 to your computer and use it in GitHub Desktop.
Save orangexception/4060217 to your computer and use it in GitHub Desktop.
Conditional SQL
-- # Conditional SQL Statements
-- This technique allows you to write a single query with conditional SQL without using the security hole of `EXECUTE`.
-- Skip The First Conditional
WHERE 1= 1
-- Conditional SQL:
-- This technique allows you to write a single query with conditional SQL without using the security hole of `EXECUTE`.
-- If @iUserStatusID is 0, then no limit is imposed.
-- If @iUserStatusID is not 0, then Users.StatusID must equal @iUserStatusID.
AND Users.StatusID=
CASE WHEN @iUserStatusID = 0
THEN Users.StatusID
ELSE @iUserStatusID
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment