How does SQL 2005 tabulate works?

Asked By 20 points N/A Posted on -
qa-featured

Hi TechyV users and forumers!

May I ask you, how is SQL 2005 tabulate data works? Can I create my own tabular data? What is the benefit of this data?
 

Thank You and Have a Good Day!

Derick Karpoff

SHARE
Answered By 0 points N/A #156005

How does SQL 2005 tabulate works?

qa-featured

 

Hello,
Here is an example to show you how to use crosstab queries PIVOT in SQL Server 2005.  In this example a table is created with 3 columns. Column SalesAss, ColumnFR1 and ColumnFR2. 
// selects the three columns
SELECT SalesAssis, [FR1] AS FR2, [FR2] AS FR2
// create cross-tab results. The (ps) used to create a temporary table for the query result. 
FROM 
(SELECT SalesAssis, Product, Amount
FROM Sales ) ps
PIVOT
(
// pvt will collect the data from the query
SUM (Amount)
FOR Product IN
( [FR1], [FR2])
) AS pvt
 
The brackets are necessary so that the pivot treats the name inside the brackets as columns.
 
I hope this is helpful.
 

Related Questions