.NET and SQL Server interview questions - Typical Complicated SQL query asked in .NET interviews to see if you know how to split columns into a row?

 Posted by ArticlesMaint on 4/25/2011 | Category: Sql Server Interview questions | Views: 13419


let's us assume that we have the following table of Employee.

Emp_IdEmp_NameEmp_Salary_2010Emp_Salary_2011
1
Shiv1700019000
2
Raju
1350015000
3
Sham1500018000
4
Moosa1100014000
5
Feroz1200016000
                     
Now we want to merge the Emp_Salary_2010 and Emp_Salary_2011 columns into a single column as Salary.
Query:-
select Emp_Name,Emp_Salary_2010 as Salary from Employee
union
select Emp_Name,Emp_Salary_2011 as Salary from Employee
Output:-
Emp_NameSalary
Shiv17000
Shiv19000
Raju
13500
Raju
15000
Sham
15000
Sham
18000
Moosa
11000
Moosa
14000
Feroz 12000
Feroz 15000

Regards,

      


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response