Solved

MS Access query to separate consolidated data into a single record

Posted on 2013-01-16
5
316 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 119

Accepted Solution

by:
Rey Obrero 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 119

Expert Comment

by:Rey Obrero
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now