Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Created November 25, 2015 21:43
Show Gist options
  • Save stevewithington/1a5aa87196e972769674 to your computer and use it in GitHub Desktop.
Save stevewithington/1a5aa87196e972769674 to your computer and use it in GitHub Desktop.
SQL: When you need a if / else / then in your WHERE clause, this might help ...
SET @someVar = 'someValue';
SELECT *
FROM t_sometable
WHERE CASE @someVar <> '' THEN someColumn = @someVar ELSE someColumn = '' END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment