Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2011
    Posts
    14

    Question Query to place names from columns to rows (not crosstab query)

    Hi there Everyone!



    I am using Access not too long ago and I would like to make a query for a report.

    The situation is the following:

    I have a table with different risks and I need to add the name of employees as risk owners to their relevant risks. It is a many to many relation (one risk can belong to many persons, and one person can be owner of multiple risks as well), therefore I made a junction table which adds the risk no. to the relevant names.

    In the attached database file you can see clearly these tables. My problem is that when I make a query on risks (I already created this query in the file) I get the results in rows....meaning that one risk has as many rows as risk owners. However I would like to have only one row per risk and then a different column for each risk owner. The maximum risk owners per risk is 5, so I would like to have something like what you can see in the "Query_should_look_like_this" table. The crosstab query is not a solution because there must be five columns (RiskOwner1, RiskOwner2, RiskOwner3, RiskOwner4, RiskOwner5) but there are more than 200 employee names in the real database, so each column holds different names per risks. For those risks that have less than 5 owners some of columns remain blank.

    What I would like to get as end result is like the "Query_should_look_like_this" table in the file.

    Is it possible to make it? Please try to help if you can because I struggling for days now and I am very desperate.

    P.S.: I need this format exactly because my boss accepts my reports only in this format (in excel).

    Thank you very much in advance!
    Attached Files Attached Files
    Last edited by hunsnowboarder; 08-15-2013 at 06:31 AM. Reason: attachment added

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,897
    I think this is going to require VBA code. Options:

    1. write records to a 'temp' table and use that table as source for output to Excel, purge the table after each execution - I use this technique for some extraordinary data manipulation, info at http://forums.aspfree.com/microsoft-...ry-322123.html

    2. concatenate the owners to a single string, review http://allenbrowne.com/func-concat.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    hunsnowboarder is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2011
    Posts
    14
    Quote Originally Posted by June7 View Post
    I think this is going to require VBA code. Options:

    1. write records to a 'temp' table and use that table as source for output to Excel, purge the table after each execution - I use this technique for some extraordinary data manipulation, info at http://forums.aspfree.com/microsoft-...ry-322123.html

    2. concatenate the owners to a single string, review http://allenbrowne.com/func-concat.html
    Wow! Thank you soo much! It seems you really understand my problem (many people didn't). The second solution would be perfect for me as in excel I will be able to make columns from rows.

    I will try it, however at this moment seems very complicated to me.

    Thank you again, I will get back with my progress.

    Thanks again!

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

Similar Threads

  1. Replies: 1
    Last Post: 03-08-2013, 12:30 PM
  2. Showing Columns & Rows in Crosstab query
    By coach32 in forum Queries
    Replies: 6
    Last Post: 09-11-2011, 07:01 PM
  3. Calculating columns in crosstab query
    By GraemeG in forum Queries
    Replies: 11
    Last Post: 06-05-2011, 06:43 PM
  4. Replies: 1
    Last Post: 01-24-2011, 03:03 PM
  5. Replies: 7
    Last Post: 09-24-2010, 07:23 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