Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




.NET and SQL Server interview questions - Which query is used to merge two different columns into single column?

Answer:

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


Please click here to see more .NET and SQL Server interview questions   
     
Regards,  
 
Visit Authors blog for more .NET and SQL Server  interview questions

Share this article   |    Print    |    Article read by 3910 times
Author:
Shivprasad koirala Koirala
I am a Microsoft MVP for ASP/ASP.NET and currently a CEO of a small E-learning company in India. We are very much active in making training videos , writing books and corporate trainings. Do visit my site http://www.questpond.com for .NET, C# , design pattern , WCF , Silverlight , LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server training and Interview questions and answers
Related Articles:
Related Interview Questions: