Link to home
Start Free TrialLog in
Avatar of AidenA
AidenA

asked on

TRANSFORM query for MS Access using .NET

Below I can't do the first query but can do the second query. The queries are the same, creating a make table query on the result of another query, but the second query has a TRANSFORM and PIVOT part while the first doesn't. So, I don't know much abou that type of query... except that it didn't work... what's the reason for that? (I mean, both simply produce a table as a result... so I don't know why I can't call that table 'Temp' and then SELECT INTO a new table called RevenueByCountryAct.

CAN'T do this query

strSQL = "SELECT Temp.* INTO RevenueByCountryAct FROM"
strSQL = strSQL + " (TRANSFORM Sum([Table1].BillAmount) AS SumOfBillAmount"
strSQL = strSQL + " SELECT [Table1].FILESOURCE, [Table1].TYPE, [Table1].[Product Code], [Table1].Service, [Table1].Service2, [Table1].Service3, [Table1].COUNTRY"
strSQL = strSQL + " FROM [Table1]"
strSQL = strSQL + " GROUP BY [Table1].FILESOURCE, [Table1].TYPE, [Table1].[Product Code], [Table1].Service, [Table1].Service2, [Table1].Service3, [Table1].COUNTRY"
strSQL = strSQL + " PIVOT [Table1].[Billing Period]) AS Temp"

Open in new window


CAN do this query

strSQL = "SELECT Temp.* INTO RevenueByCountryAct FROM"
strSQL = strSQL + " (SELECT [Table1].FILESOURCE, [Table1].TYPE, [Table1].[Product Code], [Table1].Service, [Table1].Service2, [Table1].Service3, [Table1].COUNTRY"
strSQL = strSQL + " FROM [Table1]"
strSQL = strSQL + " GROUP BY [Table1].FILESOURCE, [Table1].TYPE, [Table1].[Product Code], [Table1].Service, [Table1].Service2, [Table1].Service3, [Table1].COUNTRY"
strSQL = strSQL + ") AS Temp"

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Pres Alt+F11, Microsoft Visual Basic Help, Microsoft Jet Reference, Data Manipulation Language, SQL Subqueries - this is of interest:

Some subqueries are allowed in crosstab queries — specifically, as predicates (those in the WHERE clause). Subqueries as output (those in the SELECT list) are not allowed in crosstab queries.



Avatar of AidenA
AidenA

ASKER

thanks cyberkiwi, followed your suggestion and it worked fine. Not the way I'd prefer to do it, but it shouldn't be a problem at the same time so I'll go ahead with that.

Thanks, Aiden