SQLTeam.com | Weblogs | Forums

Pivot


#1

I'm trying to use a Pivot to return data with

Acct Year as rows and Periods 1 through 12 running across as my columns.

table name GL_Balance
fields: Acct, Period, Year,Trx_Amt

I would like the Trx Amount listed for each period


#2

THis is what I've tried. I'm getting NULL in period 1 through 9 and 10 through 12 are populating.

select *
from
GL_Balance
pivot
(
sum(trxamt)
for period in ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])
) as pvt


#3

I figured this out.

value in the period field were 01, 02, 03........


#4

Use this for dynamic number of period http://beyondrelational.com/modules/2/blogs/70/posts/10840/dynamic-pivot-in-sql-server-2005.aspx