Saturday, December 4, 2010

Select Record between Months in SQL

select ID, Name, Month from (
    select ID, Name, Month,
        case Month
            when 'January' then 1
            when 'February' then 2
            when 'March' then 3
            when 'April' then 4
            when 'May' then 5
            when 'June' then 6
            when 'July' then 7
            when 'August' then 8
            when 'September' then 9
            when 'October' then 10
            when 'November' then 11
            when 'December' then 12
           
        end as MonthNo
    from
        Emp
 ) as TempTable
 where
    MonthNo between 1 and 12 order by [Month]

No comments:

Post a Comment

Followers

Visitor No

click for free hit counter
Download a free hit counter here.