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 set serveroutput on in pl sql?

565


What is varchar data type in sql?

513


How do you write an index?

524


What is type and rowtype in pl sql?

534


What is schema in sql example?

595






what is blob? : Sql dba

560


How can you know that statistics should be updated?

597


tell me about various levels of constraint. : Sql dba

526


What is sql*plus?

565


Are stored procedures faster than queries?

520


what is 'trigger' in sql? : Sql dba

553


Does sql require a server?

523


What is the purpose of using pl/sql?

659


How do I run sql?

610


How to write a single statement that concatenates the words ?hello? And ?world? And assign it in a variable named greeting?

644