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

Is sql a programming?

932


How many parts of a pl sql block are optional?

1026


Why do you partition data?

962


What is time based sql injection?

900


What are the two different parts of the pl/sql packages?

1023


What is the requirement of self-join?

1024


Does mysql_real_escape_string prevent sql injection?

906


What is data definition language?

1041


How do I run a sql trace?

904


What is a database event trigger?

1077


Write a sql select query that only returns each name only once from a table?

956


How do you take the union of two tables in sql?

931


Write the alter statement to enable all the triggers on the t.students table.

1066


Why we use sql profiler?

907


What is sql server and ase?

971