• RSS
  • Add To My MSN
  • Add To Windows Live
  • Add To My Yahoo
  • Add To Google

Statistics

  • Entries (4)
  • Comments (0)

My Pivot 

Friday, July 1, 2011 10:48:00 AM

DECLARE @cols NVARCHAR(2000)

SELECT @cols = COALESCE(@cols + ',[' + period + ']',

'[' + period + ']')

FROM vw_12wk

 

DECLARE @query NVARCHAR(4000)

SET @query = N'SELECT office,[L C],description, '+

@cols +'

FROM

(SELECT office, [L C],description,period, actual

FROM vw_12wk ) p

PIVOT

(

sum(actual)

FOR period IN

( '+

@cols +' )

) AS pvt

'

EXECUTE(@query)

 

---------------------

office L C description 14B 13B 12B 11B 10B 09B 08B 07B 06B 05B 04B 03

0 FN4 TOTAL C/S HRS 14630 23164 23692 23257 11527 17333 21899 18658 19449 21763 21609 17653

(1 row(s) affected)

 -------------------

DECLARE @cols NVARCHAR(2000)

SELECT @cols = COALESCE(@cols + ',[' + period + ']',

'[' + period + ']')

FROM vw_12wk

 

DECLARE @query NVARCHAR(4000)

SET @query = N'SELECT office,[L C],description, '+

@cols +'

FROM

(SELECT office, [L C],description,period, actual

FROM tblTrend ) p

PIVOT

(

sum(actual)

FOR period IN

( '+

@cols +' )

) AS pvt

'

EXECUTE(@query)

---------

DECLARE @cols NVARCHAR(2000)

SELECT @cols = COALESCE(@cols + ',[' + period + ']',

'[' + period + ']')

FROM vw_12wk

 

DECLARE @query NVARCHAR(4000)

SET @query = N'SELECT office,[L C],description, '+

@cols +'

FROM

(SELECT office, [L C],description,period, actual

FROM tblTrend ) p

PIVOT

(

sum(actual)

FOR period IN

( '+

@cols +' )

) AS pvt

'

EXECUTE(@query)

 

Comments are closed on this post.