Help In Simplifying
Jan 6, 2005Hi,
Any suggestions on how to simplify this piece of code:
'locationCount'= CASE dbo.#requestsbyyeartemp.themonth when '1' then (select count(distinct location) from #requestsbyyeartemp where themonth=1)
when '2' then (select count(distinct location) from #requestsbyyeartemp where themonth=2)
when '3' then (select count(distinct location) from #requestsbyyeartemp where themonth=3)
when '4' then (select count(distinct location) from #requestsbyyeartemp where themonth=4)
when '5' then (select count(distinct location) from #requestsbyyeartemp where themonth=5)
when '6' then (select count(distinct location) from #requestsbyyeartemp where themonth=6)
when '7' then (select count(distinct location) from #requestsbyyeartemp where themonth=7)
when '8' then (select count(distinct location) from #requestsbyyeartemp where themonth=8)
when '9' then (select count(distinct location) from #requestsbyyeartemp where themonth=9)
when '10' then (select count(distinct location) from #requestsbyyeartemp where themonth=10)
when '11' then (select count(distinct location) from #requestsbyyeartemp where themonth=11)
when '12' then (select count(distinct location) from #requestsbyyeartemp where themonth=12) end
locationCount is a variable in a temp table. I am looking for ways to make things less repetitive and more efficient.
Thanks