SQL to combine values using 2 sets of parameters?

Aero11

New Member
Joined
Sep 16, 2011
Messages
34
Hello again,

I am trying to create a script that will match up multiple columns and combine the values, leaving only one unique line entry.

So, for example, I have one column with "Work Order Number" another with "Status", and one more with "Number of Days". For whatever reason, our database can have multiple instances of the same work order number and status, but with different values.

Work Order - Status - Number of Days

21104 - - - Not in Stock - - - 5
21104 - - - Not in Stock - - - 8
21104 - - - Not in Stock - - - 10

I would like to have it combine everything into

Work Order - Status Number - of Days

21104 - - - Not in Stock - - - 23


Can this be done?

I am using the MS Query tool that comes with Excel, but most Access methods work.

Thank you in advance.
 
Last edited:

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I am using the MS Query tool that comes with Excel, but most Access methods work.
I don't know much about MS Query, but this is pretty easy to do in Access using what is called an Aggregate (or Totals) Query. Your queries would "Group" the records on Work Order and Status, and then Sum the Number of Days field.

Access has examples of Aggregate Queries in their built-in help files. It is pretty simple to do.
 
Upvote 0
Hi

You should just be able to use Totals in MS Query (this is the same as doing a group by query). The SQL would look something like this:

SELECT WORK_ORDER, STATUS, SUM(NUMBER_OF_DAYS) FROM YOURTABLE GROUP BY WORK_ORDER, STATUS


HTH
DK
 
Upvote 0
Hi

You should just be able to use Totals in MS Query (this is the same as doing a group by query). The SQL would look something like this:

SELECT WORK_ORDER, STATUS, SUM(NUMBER_OF_DAYS) FROM YOURTABLE GROUP BY WORK_ORDER, STATUS


HTH
DK

Worked like a charm! Thank you!
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,285
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top