SQL case with conditions
I have a query set that contains a CASE statement that works 95% of the time ... That's another 5% due to missing data. There is other data pointing to pointers to help ... I just know if this is possible ...
So: CASE PRDE.STATUSCODE WHEN "ONLY" RETURNS "WHEN" "DAY" DELETE "WHEN" P "THEN" Pending "WHEN" THEN "Satisfied" WHEN "T" THEN "IS SET" END AS STATUS
Sometimes this field is '', but the SATISFIEDDATE text field may be filled ... Can I write something here: CASE '' THEN [if SATISFIEDDATE <> '' then 'Satisfied']
Sorry if this is just silly ... :)
+1
Sean
a source
to share
5 answers
CASE
WHEN PRDE.STATUSCODE='A' THEN 'Appealed'
WHEN PRDE.STATUSCODE='D' THEN 'Dismissed'
WHEN PRDE.STATUSCODE='P' THEN 'Pending'
WHEN PRDE.STATUSCODE='S' OR (PRDE.STATUSCODE='' AND LEN(SatisfiedDate)>0) THEN 'Satisfied'
WHEN PRDE.STATUSCODE='T' THEN 'Settled'
ELSE '?null/unknown?'
END AS STATUS
+2
a source to share
You may have a different CASE statement:
CASE '' THEN CASE WHEN SatisfiedDate != '' THEN 'Satisfied' END
An alternative might be the following:
CASE
WHEN PRDE.STATUSCODE = 'A' THEN 'Appealed'
WHEN PRDE.STATUSCODE = 'D' THEN 'Dismissed'
WHEN PRDE.STATUSCODE = 'P' THEN 'Pending'
WHEN PRDE.STATUSCODE = 'S'
OR (PRDE.STATUSCODE = '' AND SatisfiedDate != '') THEN 'Satisfied'
WHEN PRDE.STATUSCODE = 'T' THEN 'Settled'
END AS STATUS
+1
a source to share
you can do the following case arguments, either in your else clause or in your when clause
CASE PRDE.STATUSCODE
WHEN 'A' THEN 'Appealed'
WHEN 'D' THEN 'Dismissed'
WHEN 'P' THEN 'Pending'
WHEN 'S' THEN 'Satisfied'
WHEN 'T' THEN 'Settled'
else
case
when SATISFIEDDATE is not null then 'Satisfied'
end
END AS STATUS
0
a source to share