declare @tm datetime
set @tm = CONVERT(datetime,'2013-3-12')
declare @days int
select @days = case when MONTH(@tm) in(1,3,5,7,8,10,12) then 31 when MONTH(@tm) in(4,6,9,11) then 30 when MONTH(@tm) =2 and YEAR(@tm)%4 !=0 then 28 when MONTH(@tm) =2 and YEAR(@tm)%4 =0 then 29 else 0 end
select @days