Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
MGA
Starting Member
28 Posts |
Posted - 2010-09-28 : 05:57:18
|
| How to view the result of a sql statement horizontally if the result is :C1 C2 A 12 B 15 C 45i want it to be viewed in the following form and do this in the same sql statement that selects these columnsA B C12 15 45 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-09-28 : 06:05:17
|
| Read about the Pivot operator in BOL.PBUH |
 |
|
|
MGA
Starting Member
28 Posts |
Posted - 2010-09-28 : 06:31:19
|
| Ok how to use the PIVOT in the select statement if there are relationships between the tables Example:if i had these two tablescreate table Employees(Empid int constraint eid primary key,Stuff varchar(50))create table Salaries (Empid int constraint eid2 foregin key references Employees(Empid),Salary int)the table data Employees SalariesEmpid Stuff Empid salary 1 Manager 1 5000 2 technical 2 3000 3 developer 3 2000how to write a sql statement with the PIVOT operator to select the data belowManager technical developer 5000 3000 2000 |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-09-28 : 06:36:16
|
Write a query to get a resultset like thisEmpid Stuff Empid salary1 Manager 1 50002 technical 2 30003 developer 3 2000 Add the resultset in some temporary table or use a derived table or a CTE & then use the pivot operator on it.PBUH |
 |
|
|
|
|
|