Solved

MS Access query to separate consolidated data into a single record

Posted on 2013-01-16
5
367 Views
Last Modified: 2013-01-16
I've been sub-query challenged lately and I believe this is another example.  My sample DB has a XRef table with a number of fields.  Field 3, [BI_Part_nr] needs to be grouped, and then I need to run through the table multiple times for every competitor (8 are included) and pull out a comp_price where the BI_Part_nr is equal to the items listed in the grouped field.

My query should look like

BI_Part_Nr, EAT_Price, FITU_Price, HOR_Price, ect...

I tried doing it with multipe table, however I couldn't have a "where" statement for each table.  Perhaps this is done with multiple sub queries, however I didin't know how to tie them back to the grouped BI_Part_nr.

Thanks!
sampleRev.accdb
0
Comment
Question by:MCaliebe
  • 2
  • 2
5 Comments
 
LVL 7

Expert Comment

by:karunamoorthy
ID: 38783138
you can convert your db into mdb and resend pl
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 250 total points
ID: 38783139
test this query, see if this is what you want


SELECT xref.BI_Part_nr, Sum(IIf([Competitor]="Eat",[Comp_Price],0)) AS EAT_Price, Sum(IIf([Competitor]="FITU",[Comp_Price],0)) AS FITU_Price, Sum(IIf([Competitor]="HOR",[Comp_Price],0)) AS HOR_Price, Sum(IIf([Competitor]="PAR",[Comp_Price],0)) AS PAR_Price, Sum(IIf([Competitor]="PC",[Comp_Price],0)) AS PC_Price, Sum(IIf([Competitor]="TOM",[Comp_Price],0)) AS TOM_Price, Sum(IIf([Competitor]="SSP",[Comp_Price],0)) AS SSP_Price, Sum(IIf([Competitor]="WW",[Comp_Price],0)) AS WW_Price
FROM xref
GROUP BY xref.BI_Part_nr;
sampleRev4.accdb
0
 

Author Comment

by:MCaliebe
ID: 38783193
Cap,

This appears to work.  What is this query doing?  Is it looking for all the EAT, FITU..ect prices first, and then grouping?

Is using SUM dangerous, or is it asssumed there is only one price/vendor record?  BI_Part_nr field is not a Primary Key so, I suppose the chance does exisit that a duplicate BI_Part_nr/Vendor record could exists...and that would total the two prices, correct?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38783221
<Is using SUM dangerous, or is it asssumed there is only one price/vendor record?  >
NO, why would it be?

<BI_Part_nr field is not a Primary Key so, I suppose the chance does exisit that a duplicate BI_Part_nr/Vendor record could exists...and that would total the two prices, correct? >

That is Correct
0
 

Author Comment

by:MCaliebe
ID: 38783239
<Is using SUM dangerous, or is it asssumed there is only one price/vendor record?  >
NO, why would it be?

<BI_Part_nr field is not a Primary Key so, I suppose the chance does exisit that a duplicate BI_Part_nr/Vendor record could exists...and that would total the two prices, correct? >

<<That is Correct >>
I thought using SUM would be dangerous if two records exists, then the each price would be incorrect.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question