select email from mailing list
This is the query i want to use if
condition. I have a column in mailing list as unsub
. If this unsub
is true
the email should null in the selected result otherwise the email will be the selected result
Both IIF() and CASE resolve as expressions within a SQL statement and can only be used in well-defined places. The CASE expression cannot be used to control the flow of execution of Transact-SQL statements, statement blocks, user-defined functions, and stored procedures.
It is like a Shorthand form of CASE statement. We can conveniently use it when we need to decide between two options. There are three parts in IIF statement, first is a condition, second is a value if the condition is true and the last part is a value if the condition is false.
simply use a udf (User defined Function) Here you can use IF, ELSE, WHILE etc.
select case unsub when true then null else email end as email,....
from ...
see the docs for more examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With