sql - WHEN condition based on the current row value -
in select
query, put condition in case
value called isactive if current row's column type "adhoc" set value of isactive "n/a".
select case type when 'scheduled' 'scheduled' when 'adhoc' 'adhoc' else 'unknown' end 'type', case isactive when (type) = 'adhoc' 'n/a' when 0 'stopped' when 1 'active' end 'status' mytable
but getting error on line when (type) = 'adhoc' 'n/a'
:
incorrect syntax near '='.
how can make decision based on condition on current row?
your second case
based on single column, trying put condition in when
, not allowed:
case isactive when (type) = 'adhoc' 'n/a' when 0 'stopped' when 1 'active' end 'status'
i think meant (use case
without column , put conditions in when
):
case when [type] = 'adhoc' 'n/a' when isactive = 0 'stopped' when isactive = 1 'active' end 'status'
Comments
Post a Comment