Results 1 to 7 of 7
  1. #1
    BCJourney is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Location
    Cincinnati, OH
    Posts
    46

    Combine results in two different fields

    I have a table with 3 fields. [shape_type] [letter] [count] I want to extract the first word in the [shape_type], combine all that are the same shape and letter and add together the count.

    here is an example:

    current state Bevel - virtual, A, 5; Bevel - physical, A, 2;



    What I want it to return: Bevel A 7
    I don't care about the virtual or physical designation, i want to combine the two.

    thank you

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Ideally, Bevel and virtual/physical would be stored in two fields.

    I will presume there are other values besides 'Bevel' unless you say otherwise. Will there always be data? Will there always be both parts? Will there always be a hyphen?

    Try:

    SELECT Left([shape_type], InStr([shape_type],"-")-1) & [letter] As NewData, Sum([count]) As SumCount FROM tablename GROUP BY Left([shape_type], InStr([shape_type],"-")-1) & [letter];
    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
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    You could try:
    SELECT [A] & [total] AS Result, Left([shape_type],InStr([shape_type],"-")-2) & ", " & [letter] & ", " AS A, Sum(tblYourTable1.count) AS Total
    FROM tblYourTable1
    GROUP BY Left([shape_type],InStr([shape_type],"-")-2) & ", " & [letter] & ", ";

    You will need to replace tblYourTable1 with your table name.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    BCJourney is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Location
    Cincinnati, OH
    Posts
    46
    I tried both sets of code and I get the "Invalid procedure call" error each time. Maybe the actual data will make this clearer, although you both seem to know what is going on.
    Record 1:
    [field 1] Intel Based - Logical
    [field2] High
    [field 3] 856

    Record 2:
    [field 1] Intel Based - Logical
    [field2] Low
    [field 3] 13

    Record 3:
    [field 1] Intel Based - Physical
    [field2] High
    [field 3] 25

    Record 4:
    [field 1] Intel Based - Physical
    [field2] Low
    [field 3] 516

    I need to combine records 1 and 3 & records 2 and 4. The results would be:
    Intel Based High 881
    Intel Based Low 529

    Fields 1 and 2 can be combined into one, but i need field 3 in a separate field. In other words, I need to add together those classified as physical and logical into one record for each category. I would redesign the table but This is a large complicated database and this was just now requested so I don't want to re-invent the wheel.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Syntax of suggested queries are both correct. Where have you tried to use? Post the query statement and/or code for analysis.
    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.

  6. #6
    BCJourney is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Location
    Cincinnati, OH
    Posts
    46
    Code:
    SELECT DISTINCTROW data_tbl.Service_Type, data_tbl.Service_Item, Format$([data_tbl].[Billing_Month],'mmmm yyyy') AS [Billing_Month By Month], Sum(data_tbl.Service_Count) AS SumOfService_Count
    FROM data_tbl INNER JOIN Scorecard_cost_per_mgd_server_max_month ON data_tbl.Billing_Month = Scorecard_cost_per_mgd_server_max_month.MaxOfBilling_Month
    GROUP BY data_tbl.Service_Type, data_tbl.Service_Item, Format$([data_tbl].[Billing_Month],'mmmm yyyy'), Year([data_tbl].[Billing_Month])*12+DatePart('m',[data_tbl].[Billing_Month])-1
    HAVING (((data_tbl.Service_Item)="Critical" Or (data_tbl.Service_Item)="High" Or (data_tbl.Service_Item)="Medium" Or (data_tbl.Service_Item)="Low"));

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    I don't see anything in that query dealing with parsing shape_type field.
    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.

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

Similar Threads

  1. Replies: 4
    Last Post: 09-12-2013, 03:58 PM
  2. Replies: 1
    Last Post: 05-06-2013, 03:32 PM
  3. Combine Results of Two Queries
    By Ganymede in forum Queries
    Replies: 3
    Last Post: 12-28-2012, 02:00 PM
  4. How do I combine query results?
    By neha in forum Queries
    Replies: 2
    Last Post: 12-29-2011, 11:30 PM
  5. Combine query results
    By broadm in forum Queries
    Replies: 2
    Last Post: 04-15-2011, 08:37 AM

Tags for this Thread

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