Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

I want to display the employees who have joined in last two
months. (It should be executed randomly means If I execute
the query in March it should display Jan and Feb joined
employees. Same query if i execute in Feb, 2007 it should
display dec, 2006 and jan 2007 joined employees.

Answer Posted / subbu

Assuming that the Table name is "Employee" & his/her date of
joining is stored in column "JoiningDate". Below query gives
you the result


If (Month(GetDate()))=1
Select * from Employee Where (Month(JoiningDate)) in (11,12)
And Year(JoiningDate)=Year(GetDate()-1)
Else if Month(GetDate())=2
Select * from Employee Where (Month(JoiningDate)=12 And
Year(JoiningDate)=Year(GetDate()-1)) or
(Month(JoiningDate)=1 And Year(JoiningDate)=Year(GetDate()))
Else
Select * from Employee Where
Year(JoiningDate)=Year(GetDate())And
Month(JoiningDate)>=Month(GetDate()-2) And
Month(JoiningDate)<=Month(GetDate()-1)

Is This Answer Correct ?    0 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is difference between sql and mysql?

1101


What is a primary key sql?

1034


What are the events on which a database trigger can be based?

1170


Is there a pl/sql pragma similar to deterministic, but for the scope of one single sql select?

1007


How many sql core licenses do I need?

932


Why does sql need a server?

1022


i have 2 table table one 4 columns respective values a1 7,a2 6,a3 8 ,a4 12 & table two 4 colums respective values a1 7,a2 6,a3 8,a4 15.if table one & table two 3 colums same then 4th column values 1)Qes diff >5 then print 5 * diff value 2)Que diff <5 print 5

4007


List different type of expressions with the example.

929


Explain clause in sql?

1011


Show the cursor attributes of pl/sql.

1031


what is a foreign key ? : Sql dba

1068


Which constraints we can use while creating database in sql?

1059


How does postgresql compare to mysql?

1020


what is offset-fetch filter in tsql? : Transact sql

935


How do we accept inputs from user during runtime?

1045