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
Mention what are the core components of ssrs?
How to set database to be read_only in ms sql server?
Which are the third-party tools used in sql server and why would you use them?
What is difference between joins and subqueries?
Differentiate between sql temp table vs table variable?
What do you know about system database? : SQL Server Architecture
How to make remote connection in database?
Suppose you want to implement the many-to-many relationships while designing tables. How would you do it?
What are the different types of lock modes in sql server 2000?
How to list all columns in a table using odbc_columns()?
How can you manage sql azure security?
How to use column default values in insert statements in ms sql server?
what protocol both networks use? : Sql server database administration
What are triggers? How many triggers you can have on a table? How to invoke a trigger on demand?
What sql server means?