Share via

column header in access query

Anonymous
2014-12-18T22:14:42+00:00

I have a query that calculates totals for Year 1, Year 2, and Year 3 (these are my column headers).  I have a separate table X - that has values for Year 1, Year 2, and Year 3 -- these are not static years.  Is there a way to code into the query to pull in the Year values as headers from this table X?

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Duane Hookom 26,825 Reputation points Volunteer Moderator
    2014-12-19T15:24:31+00:00

    If I understand correctly, I expect you would need a unique field in the first table (tblLinda). I added an autonumber field [ID].

    Then create a cartesian/union query (qcarLinda) like:

    SELECT ID, YearNum, [Year 1] AS TheValue

    FROM tblLinda, TableX

    WHERE [PeriodNum]=1

    UNION ALL

    SELECT ID,YearNum, [Year 2]

    FROM tblLinda, TableX

    WHERE [PeriodNum]=2

    UNION ALL

    SELECT ID,YearNum, [Year 3]

    FROM tblLinda, TableX

    WHERE [PeriodNum]=3;

    Then create a crosstab based on qcarLinda:

    TRANSFORM First(qcarLinda.TheValue) AS FirstOfTheValue

    SELECT qcarLinda.ID

    FROM qcarLinda

    GROUP BY qcarLinda.ID

    PIVOT qcarLinda.YearNum;

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2014-12-19T04:12:27+00:00

    Also as a side note - these two tables do not have any common fieldsto link on.

    Without something in common it would be like tossed salad.

    How is your query 'headers'  Year 1, Year 2, Year 3 derived?

    Post the SQL of your query.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2014-12-18T22:42:25+00:00

    currently my query has these three columns with the headers Year 1, Year 2, Year 3

    table X has two columns setup as follows:   PeriodNum    YearNum

                                                                           1              2012

                                                                           2              2013

                                                                           3              2014

    table x is not static and the years will always change, how can I change the Column headers in my query to read 2012, 2013, 2014 instead of it currently reading Year 1, Year 2, Year 3

    I hope this explains it better.  Also as a side note - these two tables do not have any common fields to link on.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2014-12-18T22:35:12+00:00

     Is there a way to code into the query to pull in the Year values as headers from this table X?

    I do not follow - post example of data and what you want as result.

    Was this answer helpful?

    0 comments No comments