| Author: Pannalal Sinha 07 Nov 2009 | Member Level: Gold | Rating:  Points: 2 |
If u pass the query from code behind, it can be like this...
string query = "select empno from table1 where month(doj) >="+(DateTime.Now.Month-2)+" and month(doj) <="+(DateTime.Now.Month-1)+"";
Thanks Panna
|
| Author: vipul 07 Nov 2009 | Member Level: Diamond | Rating:  Points: 2 |
Hi, finding last two months using current month you can do this way
select case when datepart(month,GETDATE()) = 1 then convert(varchar(3),11) + '/' + convert(varchar(4),datepart(YEAR,getdate())-1) + ' , ' + convert(varchar(3),12) + '/' + convert(varchar(4),datepart(YEAR,getdate())-1) else convert(varchar(3),datepart(month,getdate())-2) + '/' + convert(varchar(4),datepart(YEAR,getdate())) + ' , ' + convert(varchar(3),datepart(month,getdate())-1) + '/' + convert(varchar(4),datepart(YEAR,getdate())) end
Please Rate This Answer If They Helpful
Thanks & Regards Patel Vipul
|