Click here to Skip to main content
15,886,542 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear sir

i want to select top 6 month record.

oct, sept,aug,....

plese tell me

thanks in advance
Posted

Hope this query solve your problem
SQL
select * from tablename where month(datecolumn)>'6'
 
Share this answer
 
Comments
Mehdi Gholam 31-Oct-11 6:49am    
HeHe posted the same, 5!
SQL
select * from tablename where month(datcolumn) > 6 
 
Share this answer
 
Comments
uspatel 31-Oct-11 6:53am    
you too 5..
Mehdi Gholam 31-Oct-11 7:25am    
Thanks
If am right, you want to retrieve the data for the last 6 months from today ?, for instance if you run the query today (31 Oct 2011) the system should be able to retrive the data between 1st May 2011 to 31 Oct 2011

If am right and the datetime column in my example is HireDate

SQL
select *
from   employees
where CAST(floor( CAST( HireDate AS FLOAT ) )AS DATETIME) between CAST(floor( CAST( DATEADD("M",-6,GETDATE()) AS FLOAT ) )AS DATETIME) +1
and CAST(floor( CAST( GETDATE() AS FLOAT ) )AS DATETIME)
 
Share this answer
 
v3
Hello Dear .
Try this query.
select * from DataTable2 where CONVERT(varchar, TimeRecorded) between CONVERT(varchar, GETDATE()) and CONVERT(varchar, DATEADD(MONTH, -6, TimeRecorded))
 
Share this answer
 
Comments
Bala Selvanayagam 1-Nov-11 15:22pm    
Ganu

Just my thoughts

Probably your where clause should be otherway round

between CONVERT(varchar, DATEADD(MONTH, -6, TimeRecorded)) and CONVERT(varchar, GETDATE())

the lower value should be first in the between & and operator; also consider what will happen if you have the time element in the TimeRecorded data column

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900