Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / DB Engine / SQL Server / June 2008

Tip: Looking for answers? Try searching our database.

How to Translate Access Crosstab Query to T-SQL

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
aushknotes - 30 Jun 2008 06:24 GMT
I have just built a crosstab query on Access & I am having trouble
translating it on to SQL Server 2000 or 2005. Browse thru the online help in
T-SQL Reference but no much help. Would you guys give a helping hand please?

MS-Access (2003)
TRANSFORM Count(DM.DMID) AS CountDMID
SELECT C29.C29DESCRIPTION AS PG
FROM C29 INNER JOIN (C4 INNER JOIN DM ON C4.C4ID = DM.C4ID) ON C29.C29ID =
DM.C29ID
WHERE (((DM.C8ALIAS)="XYZ"))
GROUP BY C29.C29DESCRIPTION, DM.C29DESCRIPTION
ORDER BY C29.C29DESCRIPTION, C4.C4DESCRIPTION
PIVOT C4.C4DESCRIPTION;

Many thanks in advance.
Plamen Ratchev - 30 Jun 2008 14:06 GMT
On SQL Server 2005 take a look at the PIVOT operator:
http://msdn.microsoft.com/en-us/library/ms177410.aspx

Have in mind PIVOT performs static pivoting (you have to know the pivot
values in advance). For dynamic pivoting (which is more like TRANSFORM) take
a look at the following articles:
http://www.sqlteam.com/article/dynamic-cross-tabs-pivot-tables
http://www.sqlmag.com/Articles/ArticleID/93907/93907.html
http://weblogs.sqlteam.com/jeffs/archive/2005/05/02/4842.aspx

HTH,

Plamen Ratchev
http://www.SQLStudio.com
aushknotes - 30 Jun 2008 23:19 GMT
Hi Plamen,

Thanks very much for your reading suggestions and the limitations on static
vs dynamic pivot tables. I guess I will probably consider executing the
Transform Crosstab query on Access DB, output the query results to a
spreadsheet or webpage then.

Many thanks!

> On SQL Server 2005 take a look at the PIVOT operator:
> http://msdn.microsoft.com/en-us/library/ms177410.aspx
[quoted text clipped - 10 lines]
> Plamen Ratchev
> http://www.SQLStudio.com 
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.