Login
Register
All Activity
Questions
Unanswered
Tags
Users
Ask a Question
About Us
986
Questions
785
Answers
Interview Preparation mode
beta
Funny Facebook Status
Enter your email address
All categories
SQL Server Interview Questions and Answers
(197)
SSIS Interview Questions and Answers
(54)
SSRS Interview Questions and Answers
(9)
SSAS Interview Questions and Answers
(29)
.NET Interview Questions and Answers
(186)
Oracle Interview Questions and Answers
(122)
Java Interview Questions and Answers
(32)
UNIX Interview Questions and Answers
(47)
Networking Interview Questions and Answers
(17)
MySQL Interview Questions and Answers
(30)
HR Interview Questions and Answers
(237)
General Interview Questions and Answers
(9)
Other Interview Questions and Answers
(8)
Job Openings
(3)
Greenplum Database Interview Questions and Answers
(5)
What is PIVOT feature in SQL Server, in MS SQL Server?
+1
vote
asked
1 year
ago
in
SQL Server Interview Questions and Answers
by
R
(
19,530
points)
–
edited
1 year
ago
by
R
sql-server-interview-question
t-sql
pivot
1 Answer
Nice?
Vote!
Best answer
PIVOT in SQL Server 2005/8 is used for crosstab queries. ie t
CarSales
--------------
CarModel Year TotalUnitsSold
-------------------------------------------------------
Accent 2008 200
i10 2008 100
Accent 2009 150
i20 2010 100
Accent 2010 50
And if we want reslult year wise
Year Accent i20 i10
2008 200 0 100
2009 150 0 0
2010 50 0 100
Then we need pivoting the table using pivot option in sql server
Select
year,Accent,i20,i10
from
(Select year ,carmodel,totalunitssold
from CarSales cs
PIVOT
(
sum(TotalUnitsSold) for carmodel
in ([Accent],[i20],]i10]
) As pvt
[Not verified as no sql server was available at the time writing answer]
Verify and let me know it works
answered
1 year
ago
by
siva
(
10,720
points)
Related questions
Nice?
Vote!
1
answer
What is SQL injection, in MS SQL Server?
asked
1 year
ago
in
SQL Server Interview Questions and Answers
by
R
(
19,530
points)
sql-server-interview-question
t-sql
sql-injection
Nice?
Vote!
1
answer
What is NTILE(), in MS SQL Server?
asked
1 year
ago
in
SQL Server Interview Questions and Answers
by
R
(
19,530
points)
sql-server-interview-question
t-sql
rank-function
rank
Nice?
Vote!
Add
Ans!
What is DENSE_RANK(), in MS SQL Server?
asked
1 year
ago
in
SQL Server Interview Questions and Answers
by
R
(
19,530
points)
sql-server-interview-question
t-sql
rank-function
rank
Nice?
Vote!
Add
Ans!
What is ROW_NUMBER(), in MS SQL Server?
asked
1 year
ago
in
SQL Server Interview Questions and Answers
by
R
(
19,530
points)
sql-server-interview-question
t-sql
rank
rank-function
rownumber
Nice?
Vote!
Add
Ans!
What is RANK (), in MS SQL Server?
asked
1 year
ago
in
SQL Server Interview Questions and Answers
by
R
(
19,530
points)
sql-server-interview-question
t-sql
rank
rank-function