It means someone has overcomplicated things. If SQL Server had a boolean data type, they'd probably have just had then true
, else false
and no comparison at the end. But because that's not possible in SQL Server, they've substituted 1
and 0
and then just compare that to 1
at the end to make it a logical comparison.
It could equally have been written as:
#PROMPT('SEL_TYPE')# = '%' OR
#PROMPT('SEL_TYPE')# = 'ALL' OR
e.evt_job = #PROMPT('SEL_TYPE')#
With no need for a CASE
expression at all.
Or even, probably, as just #PROMPT('SEL_TYPE')# IN ('%','ALL',e.evt_job)
, but some may feel that this obscures the intent a little too much.
So,
select code, wo_num, desc from table1
where org = #PROMPT('SEL_ORG')# and
CASE
WHEN #PROMPT('SEL_WO_TYPE')# = '%' then 1
WHEN #PROMPT('SEL_WO_TYPE')# = 'ALL' then 1
WHEN e.evt_jobtype = #PROMPT('SEL_WO_TYPE')# then 1 ELSE 0 END = 1
and e.evt_type in (''A,'B')
Could have more simply been written as:
select code, wo_num, desc from table1
where org = #PROMPT('SEL_ORG')# and
e.evt_type in (''A,'B') and
(
#PROMPT('SEL_TYPE')# = '%' OR
#PROMPT('SEL_TYPE')# = 'ALL' OR
e.evt_job = #PROMPT('SEL_TYPE')#
)
Someone wrote a CASE
expression (and then had to introduce the 1
s and 0
s) when all they needed was basic boolean logic.