Solved

MS Access query to separate consolidated data into a single record

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

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…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

786 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