?
Solved

MS Access Query Help For Graph Preparing

Posted on 2016-11-12
13
Medium Priority
?
24 Views
Last Modified: 2016-11-12
I need help with setting up a query. I don't know if I need multiple queries or if I can get this all in one.

I have 4 conditions for products. I am wanting to make a query that shows all inventory cost. Quantity * Price kind of thing.

I have successfully been able to do this with all inventory conditions. But I can't figure out how to show them all separate in a single query. I am preparing for a graph page. 4 Conditions are NSOP, NSSP, USOP, USSP.

Total: [qtyloc]*[Price]
(ProdLocations.QtyLoc)>0)

NSOP Total: [qtyloc]*[Price]
[Products].[ConditionId]=1

NSOP Total: [qtyloc]*[Price]
[Products].[ConditionId]=2

USOP Total: [qtyloc]*[Price]
[Products].[ConditionId]=3

USSP Total: [qtyloc]*[Price]
[Products].[ConditionId]=4


Thanks!
0
Comment
Question by:Dustin Stanley
[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
  • 7
  • 5
13 Comments
 
LVL 30

Expert Comment

by:hnasr
ID: 41885040
I have successfully been able to do this with all inventory conditions
Share with us what you have done, by uploading a sample database, to take off from that point.
0
 

Author Comment

by:Dustin Stanley
ID: 41885042
I have this but it shows all the same values. Which is the Total Value of All Conditions:

SELECT [qtyloc]*[Price] AS Total, ProdLocations.QtyLoc, [qtyloc]*[Price] AS [NSOP Total], [qtyloc]*[Price] AS [NSSP Total], [qtyloc]*[Price] AS [USOP Total], [qtyloc]*[Price] AS [USSP Total]
FROM Products INNER JOIN ProdLocations ON Products.ProductID = ProdLocations.ProductID
WHERE (((ProdLocations.QtyLoc)>0)) OR (((Products.ConditionId)=1)) OR (((Products.ConditionId)=2)) OR (((Products.ConditionId)=3)) OR (((Products.ConditionId)=4));

Open in new window

0
 

Author Comment

by:Dustin Stanley
ID: 41885043
I can't upload any databases currently
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41885048
try creating a total query like this

select Products.productid, sum(iif(ProdLocations.QtyLoc)>0,[qtyloc]*[Price],0) as Total
, sum(iif(ProdLocations.QtyLoc)>0,[qtyloc]*[Price],0) as Total
,sum(iif([Products].[ConditionId]=1, [qtyloc]*[Price],0) as [NSOP Total]
,sum(iif([Products].[ConditionId]=2, [qtyloc]*[Price],0) as [NSSP Total]
,sum(iif([Products].[ConditionId]=3, [qtyloc]*[Price],0) as [USOP Total]
,sum(iif([Products].[ConditionId]=4, [qtyloc]*[Price],0) as [USSP Total]
From Products
group by  Products.productid

change productID field with correct field name
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41885051
try this one

select Products.productid, sum(iif(ProdLocations.QtyLoc)>0,[qtyloc]*[Price],0) as Total
 ,sum(iif(ProdLocations.QtyLoc)>0,[qtyloc]*[Price],0) as Total
 ,sum(iif([Products].[ConditionId]=1, [qtyloc]*[Price],0) as [NSOP Total]
 ,sum(iif([Products].[ConditionId]=2, [qtyloc]*[Price],0) as [NSSP Total]
 ,sum(iif([Products].[ConditionId]=3, [qtyloc]*[Price],0) as [USOP Total]
 ,sum(iif([Products].[ConditionId]=4, [qtyloc]*[Price],0) as [USSP Total]
 From Products INNER JOIN ProdLocations ON Products.ProductID = ProdLocations.ProductID
 group by  Products.productid
0
 

Author Comment

by:Dustin Stanley
ID: 41885052
It says syntax error highlights as before NSOP
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41885055
missing ")"

select Products.productid, sum(iif(ProdLocations.QtyLoc)>0,[qtyloc]*[Price],0)) as Total
  ,sum(iif(ProdLocations.QtyLoc)>0,[qtyloc]*[Price],0)) as Total
  ,sum(iif([Products].[ConditionId]=1, [qtyloc]*[Price],0)) as [NSOP Total]
  ,sum(iif([Products].[ConditionId]=2, [qtyloc]*[Price],0)) as [NSSP Total]
  ,sum(iif([Products].[ConditionId]=3, [qtyloc]*[Price],0)) as [USOP Total]
  ,sum(iif([Products].[ConditionId]=4, [qtyloc]*[Price],0)) as [USSP Total]
  From Products INNER JOIN ProdLocations ON Products.ProductID = ProdLocations.ProductID
  group by  Products.productid
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41885056
try this one

select Products.productid
, sum(iif(ProdLocations.QtyLoc)>0,[qtyloc]*[Price],0)) as Total  
   ,sum(iif([Products].[ConditionId]=1, [qtyloc]*[Price],0)) as [NSOP Total]
   ,sum(iif([Products].[ConditionId]=2, [qtyloc]*[Price],0)) as [NSSP Total]
   ,sum(iif([Products].[ConditionId]=3, [qtyloc]*[Price],0)) as [USOP Total]
   ,sum(iif([Products].[ConditionId]=4, [qtyloc]*[Price],0)) as [USSP Total]
   From Products INNER JOIN ProdLocations ON Products.ProductID = ProdLocations.ProductID
   group by  Products.productid
0
 

Author Comment

by:Dustin Stanley
ID: 41885057
it keeps saying wrong number of arguments for:
sum(iif(ProdLocations.QtyLoc)>0,[qtyloc]*[Price],0) as Total   

Open in new window


I've been trying trying to figure it out
0
 

Author Comment

by:Dustin Stanley
ID: 41885058
Sorry I meant

sum(iif(ProdLocations.QtyLoc)>0,[qtyloc]*[Price],0) as Total
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 41885059
select Products.productid
 , sum(iif([ProdLocations].[QtyLoc]>0,[qtyloc]*[Price],0)) as Total  
    ,sum(iif([Products].[ConditionId]=1, [qtyloc]*[Price],0)) as [NSOP Total]
    ,sum(iif([Products].[ConditionId]=2, [qtyloc]*[Price],0)) as [NSSP Total]
    ,sum(iif([Products].[ConditionId]=3, [qtyloc]*[Price],0)) as [USOP Total]
    ,sum(iif([Products].[ConditionId]=4, [qtyloc]*[Price],0)) as [USSP Total]
    From Products INNER JOIN ProdLocations ON Products.ProductID = ProdLocations.ProductID
    group by  Products.productid
0
 

Author Comment

by:Dustin Stanley
ID: 41885083
Sorry I didn't respond right back as I had to leave for a bit. Also Thanks so much Rey that last one nailed it. Thanks.
0
 

Author Closing Comment

by:Dustin Stanley
ID: 41885084
Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

770 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