Solved

MS Access query to separate consolidated data into a single record

Posted on 2013-01-16
5
373 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

734 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