examples if else sql server where
Example 1: sql if else
-- PL/SQL
BEGIN
IF my_val = 1 THEN [...]
ELSE [...]
END IF;
END;
-- In a query (DUAL is for Oracle)
SELECT CASE WHEN my_col = 1 THEN 'Ok' ELSE 'Ko' END AS my_result
FROM DUAL;
Example 2: t-sql if else
IF 1=1
SELECT 1
ELSE
SELECT 0
-- returns 1
-- Definition
IF Boolean_expression
{ sql_statement | statement_block }
[ ELSE
{ sql_statement | statement_block } ]