Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have table called 'Open_Months' with below columns, there is only record for every client

Emp_Id  Month    Year     Name            Created Date             Type
00FBG	 2	2014	prakasan	2014-01-12 10:21:54.730	   R   


how to get the current months previous 2 months records

Regards,
Abhishek Patil


PUTTU PATIL
Posted
Updated 10-Feb-14 18:42pm
v2

You can try this

SQL
select *
from YourTable
where Time_Open > dateadd(month, datediff(month, 0, GETDATE()) - 4, 0)
and Time_Open < dateadd(month, datediff(month, 0, GETDATE()) - 1, 0)
 
Share this answer
 
I have table 'Open_Months' as shown below

Emp_Id Month Year
00FBG 4 2013
I need current month and previous 2 months, for this i have concatinated month and year column into date formate, the query for this as shown below

SELECT cast(CONVERT(datetime, CONVERT(varchar(4), OM_Year) + RIGHT('0' + CONVERT(varchar(2), OM_Month), 2) + '01', 112) AS Datetime) from Open_Months where OM_Emp_ID = '00FBG'

Date
2013-04-01
from the above date i need to find current month and its previous 2 months.

Regards,

AbhiShek Patil
 
Share this answer
 

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