C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » .NET »

Query


Posted Date: 07 Nov 2009      Posted By: Deepthi      Member Level: Silver     Points: 1   Responses: 2



i have a table which has 2 fields, 'DOJ' and 'Empno'.now i wanna a query which returns all empnos who have joined 2 months back the current month.(year should also be considered i.e if current mon is jan 2009, then i want empnos who joined in dec & nov of 2008).

i hope u got me.

Thanks in advance
Deepthi





Responses

Author: Pannalal Sinha    07 Nov 2009Member Level: GoldRating: 2 out of 52 out of 5     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 2009Member Level: DiamondRating: 2 out of 52 out of 5     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



Post Reply
You must Sign In to post a response.
Next : Dynamic Controls
Previous : How to print back to back pages in vb.net
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use