Skip to content

Instantly share code, notes, and snippets.

@aev-mambro2
Last active February 4, 2021 20:08
Show Gist options
  • Save aev-mambro2/8d41f8b89924576e5d194ac551e538ca to your computer and use it in GitHub Desktop.
Save aev-mambro2/8d41f8b89924576e5d194ac551e538ca to your computer and use it in GitHub Desktop.
a gist
Use IFF for field expressions in TSQL
TSQL, Microsoft's SQL dialect for SQLServer, does not accept simple equations and expressions in place of its fields.
So this it won't execute:
SELECT NAME='aev-mambro2' as Found FROM USERS;
Instead, Microsoft wants us to use IIF as a field expression, like so:
SELECT IIF(NAME='aev-mambro2',1,0) as Found FROM USERS;
Also note that TSQL does not know TRUE and FALSE as constant values. It does not know truthy or falsy expressions or statements. Instead, we must return a 1 (true) or a 0 (false).
Happy coding!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment