Created
November 12, 2012 16:12
-
-
Save orangexception/4060217 to your computer and use it in GitHub Desktop.
Conditional SQL
This file contains hidden or 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
-- # 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