Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Crosstab VBA to SQL 2005 Pivot code

Author  Topic 

rebooot
Starting Member

9 Posts

Posted - 2009-11-30 : 21:10:17
Hello all,
I am attempting to convert this VBA code in my MS-Access database to SQL server 2005. I can't do it for some reason. I would appreciate your help greatly:

PARAMETERS SQLPeriodIndex Text ( 255 ), theMarket Text ( 255 ), theSegment Text ( 255 );
TRANSFORM Sum(Choose([SQLPeriodIndex],[L4],[L12],[L24],[L52],[YTD],[YTG])) AS SumOf
SELECT Data_3.Tag
FROM Data_3 INNER JOIN SKU_CONTENTS ON Data_3.Tag=SKU_CONTENTS.TAG
WHERE (((Data_3.Market)=[theMarket]) AND ((SKU_CONTENTS.SEGMENT)=[theSegment]))
GROUP BY Data_3.Tag
PIVOT Data_3.Fact;

I can even make SQLPeriodIndex another variable to passed to the code, but I need the PIVOT equivalent in SQL Server.

Thank you so much.

I hope someone is up tonight working.

Regards to all,

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-01 : 01:55:29
Refer this
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -