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
Which tcp/ip port does sql server run on? How can it be changed? : Sql dba
Why use subqueries instead of joins?
How to select 10 records from a table?
How many tables can a sql database have?
how to do backup entire database? : Transact sql
What are commit, rollback, and savepoint?
What is on delete set null?
What is online transaction processing (oltp)?
What are the commands used in sql?
Explain select statements in sql?
Is sql microsoft?
How to Execute a Package in PL/SQL.?
How can we find duplicate records in a table?
What is a table?
write an sql query to get third maximum salary of an employee from a table named employee_table. : Sql dba