I Have Employee table having column name as ID,SALARY
how to get second max salary from employee table with id
ex
ID SALARY
1 20000
7 37000
2 5000
Answer Posted / ankit nanda
Do onething
just create a function which use the three input parameters
and
while select * from ComputeEmployee(,,,)insert one of the
designation or salary or department at a time or wtever u
want....here i used some case statement to solve the
problem..wheeeeww...one thing else uniqueidentifier i just
use for the column type,u can use a simple int also ::))
create function ComputeEmployee(@Designation nvarchar
(100),@Department nvarchar(100),@Salary bigint)
returns @DemoTable table (EmployeeID
uniqueidentifier,Designation Nvarchar(100),Name Nvarchar
(100),Department Nvarchar(100),Salary bigint)
as
begin
insert into @DemoTable
select
ed.EmployeeID,ed.Designation,ed.Name,sd.Department,sd.Salary
from EmployeeDetails ed inner join
SalaryDetails sd on sd.SalaryID=ed.EmployeeID
where ed.Designation like case when
@Designation IS not null then '%'+@Designation+'%' end
AND sd.Department like case when
@Department IS not null then '%'+@Department+'%' end
AND sd.Salary =case when @Salary Is not
null then @Salary else sd.Salary end
return
end
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is the default fill factor value?
What do you understand by sql server agent?
What are security principals used in sql server 2005?
What is scalar user-defined function?
How you can get a list of all the table constraints in a database?
What is repeatable read?
How to find the second highest salary of an employee?
How to name query output columns in ms sql server?
How to update muliple row in single query?
Explain what is “asynchronous” communication in sql server service broker?
What is the difference between a function and a trigger?
What is a self join in sql server?
Why do you want to join software field as you have done your BE in Electronics?
how to invoke a trigger on demand? : Sql server database administration
What is a data collection table?