Results 1 to 5 of 5
  1. #1
    smg is offline Competent Performer
    Windows XP Access 2010 64bit
    Join Date
    Apr 2019
    Posts
    121

    SQL statement to put similar values into one column, not a concatentate

    I have a form that allows the user to add three Error Precursors to an item like this:
    ErrorPrecursor1 ErrorPrecursor2 ErrorPrecursor3
    TD-7



    TD-1 TD-3 WE-2
    WE-3 TD-1 HN-1
    HN-2

    TD-7

    WE-1

    HN-2

    HN-4 HN-5
    IC-7

    TD-7 TD-8
    TD-7 HN-2
    WE-4

    TD-6

    HN-4

    HN-4

    HN-4

    HN-4

    HN-4

    TD-8

    HN-5 HN-7
    HN-4

    HN-5

    I need a query that will provide a list of all Errors like this in one column:
    All Error Precursors
    TD-7
    TD-1
    WE-3
    HN-2
    TD-7
    WE-1
    HN-2
    HN-4
    IC-7
    TD-7
    TD-7
    WE-4
    TD-6
    HN-4
    HN-4
    HN-4
    HN-4
    HN-4
    TD-8
    HN-5
    HN-4
    HN-5
    TD-3
    TD-1
    HN-5
    TD-8
    HN-2
    HN-7
    WE-2
    HN-1

    Please help with a sql statement to do this.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    smg,

    When readers see fields with names like Field1, Field2, Field3.....FieldX, the immediate reaction is "probably poor table structure". It seems this data should be put into its own table along with some unique identifier. Whether or not this is the case here really depends on your application.
    Can you give us an overview of what you are dealing with --in simple English - and how he pieces fit together in the business this database is intended to support?

    Please show us the tables and relationships you have currently.
    Good luck with your project.

  3. #3
    Peter M is offline Advanced Beginner
    Windows 7 64bit Access 2013 32bit
    Join Date
    Dec 2017
    Posts
    67
    Agree with Orange that if you are still early in the design stage, replace with ErrorPrecursor, ErrorPrecursorCount.

    BUT to answer your question, use a Union query.

    Select {fields that are all the same}, ErrorPrecursor1 as ErrorPrecursor, 1 as ErrorPrecursorCount from tbl_Table
    UNION
    Select {fields that are all the same}, ErrorPrecursor2 as ErrorPrecursor, 2 as ErrorPrecursorCount from tbl_Table
    UNION
    Select {fields that are all the same}, ErrorPrecursor3 as ErrorPrecursor, 3 as ErrorPrecursorCount from tbl_Table;

    Save that as TemproraryQuery and then run a Make table query to pull all the data into a single narrow table where ErrorPrecursor is not null.

  4. #4
    smg is offline Competent Performer
    Windows XP Access 2010 64bit
    Join Date
    Apr 2019
    Posts
    121
    ok, so far so good. I used the following sql statement:
    Select ErrorPrecursor1 as ErrorPrecursor from AssessmentDetail
    UNION
    Select ErrorPrecursor2 as ErrorPrecursor from AssessmentDetail
    UNION
    Select ErrorPrecursor3 as ErrorPrecursor from AssessmentDetail
    and got the following result:
    ErrorPrecursor

    HN-1
    HN-2
    HN-4
    HN-5
    HN-7
    IC-7
    TD-1
    TD-3
    TD-6
    TD-7
    TD-8
    WE-1
    WE-2
    WE-3
    WE-4


    now, I would like to get a count of each code, for instance, between the three ErrorPrecursor columns, HN-4 has a count of 7.
    Thanks

  5. #5
    smg is offline Competent Performer
    Windows XP Access 2010 64bit
    Join Date
    Apr 2019
    Posts
    121
    I went back to design and created a multi-field combo box instead. Thanks for all the help.

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

Similar Threads

  1. Replies: 14
    Last Post: 07-13-2015, 12:47 PM
  2. Match similar values
    By enjiel in forum Queries
    Replies: 6
    Last Post: 04-09-2014, 06:44 PM
  3. Replies: 4
    Last Post: 10-24-2011, 11:14 AM
  4. Replies: 1
    Last Post: 04-15-2010, 02:07 AM
  5. Replies: 1
    Last Post: 01-22-2010, 03:21 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