Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
PUTTU PATIL
Starting Member
7 Posts |
Posted - 2014-02-10 : 23:58:58
|
I have table 'Open_Months' as shown belowEmp_Id Month Year00FBG 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 belowSELECT 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' Date2013-04-01 from the above date i need to find current month and its previous 2 months.Regards,AbhiShek Patil |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-02-11 : 00:19:06
|
[code]select * from Open_Months where Emp_ID = '00FBG' and [Year]=YEAR(GETDATE())and [Month] BETWEEN MONTH(DATEADD(mm,-2,GETDATE())) AND MONTH(GETDATE())[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|