Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Convert table View
Message
 
 
À
09/04/2008 09:01:15
Issam Mansour
Jordan Business Machines
Amman, Jordanie
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01309263
Message ID:
01309551
Vues:
7
>Hi,
>I have an accounting table with 5 year of data for an account, the table headers look as following
>
>Acctno___Year___db_1,db_2,db,db_3,db4,….db_12,Cr_1,cr_2,cr_3…,cr-12
>
>I want to with select statement to convert the data to query the header must be the following:-
>
> Years1___Year2___year3___year4____year5
>Db_1
>Db_2
>Db_3
>.
>.
>.
>
>Thanks for any help

I'm not sure I follow exactly what you want to achieve. Can you provide the create table script with few inserts and then what exactly do you want to achieve?

I can type you the sample from the book, but I'm not sure how would it help you:
select CustomerID, [2001] as Y2001, [2002] as Y2002, [2003] as Y2003, [2004] as Y2004 
from
(select CusrtomerID, DATEPART(yyyy, OrderDate) as OrderYear, TotalDue
from Sales.SalesOrderHeader) piv
PIVOT
(SUM(TotalDue) FOR OrderYear IN ([2001],[2002],[2003],[2004]) AS chld 
ORDER BY CustomerID
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform