Results 1 to 3 of 3
  1. #1
    linvall is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    29

    Select distinct values one column into multiple columns

    I have a table with work orders (col 1) and a bunch hold codes (col 2), like in Ex1. Certain work orders can have multiple hold codes and will be repeated in col 1. Is there a way to make all the unique hold codes appear in the same column separated by a comma (Ex2) or in the same row but different columns (Ex3)? Thanks



    Click image for larger version. 

Name:	EX1.PNG 
Views:	6 
Size:	1.6 KB 
ID:	38148
    Click image for larger version. 

Name:	EX2.PNG 
Views:	6 
Size:	2.2 KB 
ID:	38149
    Click image for larger version. 

Name:	EX3.PNG 
Views:	6 
Size:	1.6 KB 
ID:	38150

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Example numbers in your narrative don't correspond with the images but I understand regardless.

    Ex2 would be a CROSSTAB query. A CROSSTAB requires 3 fields minimum. So will have to calculate 3rd field. This will be a sequence number for each order group that will become the column headers. Need a unique record identifier - autonumber field should serve.

    TRANSFORM First(Table1.Col2) AS FirstOfCol2
    SELECT Table1.Col1
    FROM Table1
    GROUP BY Table1.Col1
    PIVOT DCount("*","Table1","Col1=" & [Col1] & " AND ID<" & [ID])+1;

    Ex3 would use VBA 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
    linvall is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    29
    Thanks for this, I will take a look at this over the weekend.

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

Similar Threads

  1. Replies: 4
    Last Post: 12-14-2016, 05:20 PM
  2. Replies: 1
    Last Post: 04-30-2014, 01:05 AM
  3. Replies: 1
    Last Post: 03-28-2013, 11:10 PM
  4. Sql code for Distinct column and two other Columns
    By vaiofoxx1 in forum Programming
    Replies: 3
    Last Post: 03-22-2012, 09:24 AM
  5. Replies: 2
    Last Post: 12-05-2011, 04:53 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