I hate code that looks like its been hacked together. I have just written this:
update table1.dbo.totals
set @FEE = case
when isnull(g.SGROUPS,0) > 1
then @GROUPPRICE * case
when CHARINDEX('JMCG', g.GROUPS) > 0
then (g.SGROUPS - 2)
else (g.SGROUPS - 1)
end
else 0
end
from @GROUPMEM as g
if @FEE < 0
begin
set @GROUPFEE = 0
end
I'm particularly wanting to get rid of that nested CASE. Any suggestions?