Results 1 to 4 of 4
  1. #1
    tmartin is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    37

    Create crosstab query without a intermediate table

    The enclosed code is a prototype that first creates an intermediate table called temp and then used by the crosstab query. I have enclosed the SQL. Is there anyway
    to use a UNION and eliminate the need for two separate queries with a temporary table?

    Thanks
    TOm
    Attached Files Attached Files

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    If you convert your make table query to a select query. you could just use this as the source for the crosstab which eliminates the need for a temp table, or you could just convert the second query into a crosstab query.

    Code:
    TRANSFORM Sum([Cost]+[Service Charge]) AS SumOfTotal
    SELECT Employees.FirstName
    FROM Employees INNER JOIN [Transaction] ON Employees.EmployeeID = Transaction.EmployeeID
    WHERE (((Transaction.Date) Between [Forms]![PreReport]![startDate] And [Forms]![PreReport]![endDate]))
    GROUP BY FirstName
    PIVOT [Type];
    Note that type is a reserved word, using it can have unexpected consequences, better to change the name to something else

  3. #3
    tmartin is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    37

    Prototype Enclosed

    I manually tried inserting your SQL in SQL view and did get errors. I put together this prototype that you run from the Form
    If you specify a date range it will generate a report but has the intermediate steps. If this helps let me know

    Tom
    Attached Files Attached Files
    Last edited by tmartin; 05-24-2015 at 08:55 PM. Reason: Double check uploaded file

  4. #4
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    Code:
    TRANSFORM Sum([Cost]+[Service Charge]) AS Total
    SELECT Employees.FirstName
    FROM Employees INNER JOIN [Transaction] ON Employees.EmployeeID = Transaction.EmployeeID
    WHERE (((Transaction.Date) Between [Forms]![PreReport]![startDate] And [Forms]![PreReport]![endDate]))
    GROUP BY Employees.FirstName
    PIVOT Transaction.Type;
    this works except that it cannot find startdate and enddate in your prereport form - you have called them something else

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 05-17-2017, 07:41 AM
  2. Table like a crosstab query but not
    By CodLiverOil in forum Reports
    Replies: 5
    Last Post: 05-18-2015, 12:08 PM
  3. Replies: 1
    Last Post: 07-17-2013, 02:34 PM
  4. Replies: 37
    Last Post: 01-29-2013, 10:50 AM
  5. Replies: 1
    Last Post: 07-30-2010, 10:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums