.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_Id | Emp_Name | Emp_Salary_2010 | Emp_Salary_2011 | 1
| Shiv | 17000 | 19000 | 2
| Raju
| 13500 | 15000 | 3
| Sham | 15000 | 18000 | 4
| Moosa | 11000 | 14000 | 5
| Feroz | 12000 | 16000 |
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_Name | Salary | Shiv | 17000 | Shiv | 19000 | 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,
http://
http://
Contributed by:
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
Resourse address on xpode.com
http://www.xpode.com/Print.aspx?Articleid=408
Click here to go on website
|