Hay un operador ternario en T-Sql?


¿Cuáles son las alternativas para implementar la siguiente consulta:

select *  
from table  
where isExternal = @type = 2 ? 1 : 0
Author: styfle, 2013-04-25

2 answers

Use case:

select *
from table
where isExternal = case @type when 2 then 1 else 0 end
 94
Author: Guffa,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-04-25 08:22:36

En SQL Server 2012, usted podría utilizar el IIF función :

SELECT *
FROM table
WHERE isExternal = IIF(@type = 2, 1, 0)

También tenga en cuenta: en T-SQL, el operador de asignación (y comparación) es simplemente = (y no == - eso es C#)

 117
Author: marc_s,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-07-17 12:36:13