PS. Forgot to say, I am using SQL 2000, to the PIVOT comment doesn't exist on it.
Main Topics
Browse All TopicsI have the following query in Access that uses two tables (a Fund table storing Mutual fund information and a ReturnPoint table storing monthly returns for each fund, they are linked by the Fund ID) and a PIVOT command on the Date field:
TRANSFORM Sum(dbo_tblReturnPoint.Ret
SELECT dbo_tblFund.ID
FROM dbo_tblFund INNER JOIN dbo_tblReturnPoint ON dbo_tblFund.ID = dbo_tblReturnPoint.FundID
WHERE (((dbo_tblFund.ID)<5) AND ((dbo_tblReturnPoint.Date)
GROUP BY dbo_tblFund.ID
PIVOT dbo_tblReturnPoint.Date;
The output produced by the query consists of a matrix with the Fund Ids on the first column,
the return dates on the first row and the return values inside as shown below
(if a fund returns is missing on a particular date, the cell is blank):
ID 1/31/2006 2/28/2006 3/31/2006 4/30/2006 5/31/2006 6/30/2006 7/31/2006 8/31/2006 9/30/2006 10/31/2006 11/30/2006 12/31/2006 1/31/2007 2/28/2007 3/31/2007
1 0.0181905 0.0033673 0.007551 0.0076795 -0.0006427 0.0028 0.0038 0.0003 0.0032 0.0155 0.009941782 0.008513657 0.024973619 0.0045
2 0.0027 0.0029 -0.003 -0.0059 -0.0184 0.0027 0.002936 -0.005044 -0.007826 -0.019376 -0.000042 0.010312 0.0116
3 0.0076272 0.0263006 -0.0735671 -0.0312373 0.0177 -0.0116 -0.0807 0.0704 0.0767 0.0536 0.0009 0.0487 0.0034 0.012
4 0.0641 0.012 0.0469 0.0066 -0.0581 -0.020400001 -0.0903 0.0317 0.0198 0.0118 0.069399998 -0.0106 0.057 -0.034 0.023
My question is: how do I port the above query to MSSQL where the PIVOT command doesn't exist?
Thanks,
Stefano
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
if you want to spend a little money, and save yourself some time, you could try RAC (not used it myself tho):
http://www.rac4sql.net/rac
However, you could also try one of the flavours of sp_CrossTab which have been posted out there:
sp_JRMCrossTab
http://www.johnmacintyre.c
Dynamic Crosstab Queries By: Itzik Ben-Gan
http://www.sqlmag.com/Arti
Business Accounts
Answer for Membership
by: DireOrbAntPosted on 2007-05-08 at 19:56:32ID: 19054415
http://www.databasejournal .com/featu res/mssql/ article.ph p/ 3516331
.com/featu res/mssql/ article.ph p/ 3516331
Check the second page.
Also, note that SQL 2005 support PIVOT:
http://www.databasejournal