Reputation: 654
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 September
how to write a query to select data between January and April
Upvotes: 0
Views: 784
Reputation: 700800
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')
Upvotes: 1
Reputation: 19612
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
Upvotes: 3