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?
Ok so this a little odd but may be cool. It gets rid of your nested case and uses some bitwise operations…
You’re probably asking what
(g.SGROUPS^1)&1does… This basically converts g.SGROUPS to one if it has a value, allowing us to use it in the multiplication.