Here is the condition,i have a table with the records for every months per year.
I would like to retrieve the records only for three months per year.
Lets make this clear, the records would be around Jan~Mar or Apr~Jun or July~Sept or Oct~Dec.
Current date is 1-May-2011, so the records around Apr~Jun would be selected.
Anyway how to write it in SQL statement?

what is the exact table structure ?

Try something like this in the where clause..
i assume that u store month id in your table.


where
(
(monthid in (1,2,3) and month(getdate()) in (1,2,3))
or
(monthid in (4,5,6) and month(getdate()) in (4,5,6))
or
(monthid in (7,8,9) and month(getdate()) in (7,8,9))
or
(monthid in (10,11,12) and month(getdate()) in (10,11,12))
)

use datediff() in query and take difference in year from today to last 3 month

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.