j.miner (4/8/2013)
select @var_months3 =(
case
when @var_cnt = 1 then 'jan'
when @var_cnt = 2 then 'feb'
when @var_cnt = 3 then 'mar'
when @var_cnt = 4 then 'apr'
when @var_cnt = 5 then 'may'
when @var_cnt = 6 then 'jun'
when @var_cnt = 7 then 'jul'
when @var_cnt = 8 then 'aug'
when @var_cnt = 9 then 'sep'
when @var_cnt = 10 then 'oct'
when @var_cnt = 11 then 'nov'
when @var_cnt = 12 then 'dec'
else 'unk'
end
)
Just as a suggestion... please consider the following which takes a whole lot less typing and is twice as fast when running.
SELECT @var_months3 = CONVERT(CHAR(3),DATEADD(mm,@var_cnt-1,0),100);
For proof of the performance pudding, please see the following article.
http://www.sqlservercentral.com/articles/formatting/72066/
--Jeff Moden
Change is inevitable... Change for the better is not.