How to select Month Between in SQL
ID Name **Month(Varchar column)**
23 Raj January
435 Amit Kumar February
54 Mohan March
546 Mohan March
56 Raj January
57 Ani December
58 Moni April
59 Soni Septemb开发者_如何学Cer
how to write a query to select data between January and April
You would make your job much more easy if you would store actual dates or month numbers.
If you have to live with the current table structure, you need to translate the month names into their corresponding number. Theses numbers can be compared:
select ID, Name, Month from (
select ID, Name, Month,
case Month
when 'January' then 1
when 'February' then 2
...
end as MonthNo
from
Table
) as TranslatedTable
where
MonthNo between 1 and 4
As your data is not comparable, you would need to supply all possible values in the range:
select ID, Name
from TheTable
where Month in ('January', 'February', 'March', 'April')
精彩评论