Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Access: adding the results of SQL queries

Status
Not open for further replies.

L1sta

Technical User
Feb 22, 2007
14
GB
Hi
I'm trying to develop a calculator in Ms Access which will calculate the cost of calibrators, QCs and reagents (but not consumables) in storage for a specific study.
My problem is that when I run the query below the results come back as 3 separate values whereas I need one.
I was considering running three separate queries and adding the results but I can't make this work either. Can anyone help??

Lista


Code:
SELECT DISTINCT Sum(tblDetails.Cost) AS SumOfCost, tblStudyNo.StudyProtocolNumber, tblItem.Status, tblDetails.Category
FROM tblStudyNo INNER JOIN (tblDetails INNER JOIN tblItem ON tblDetails.DetailNo = tblItem.DetailsNo) ON tblStudyNo.StudyProtocolNumber = tblDetails.StudyNo
GROUP BY tblStudyNo.StudyProtocolNumber, tblItem.Status, tblDetails.Category
HAVING (((tblStudyNo.StudyProtocolNumber)=[parameter1]) AND ((tblItem.Status)='in storage') AND ((tblDetails.Category)<>"Consumable"));
 
Code:
SELECT DISTINCT Sum(tblDetails.Cost) AS SumOfCost, 
FROM tblStudyNo INNER JOIN tblDetails INNER JOIN tblItem ON tblDetails.DetailNo = tblItem.DetailsNo ON tblStudyNo.StudyProtocolNumber = tblDetails.StudyNo
and(((tblStudyNo.StudyProtocolNumber)=[parameter1]) AND ((tblItem.Status)='in storage') AND ((tblDetails.Category)<>"Consumable"));
 
Hi
Thanks for the quick reply but I cant get this to work... lots of syntax errors and 'Join type not supported' messages.
If it matters, I'm using Access 2003

Lista
 
try
[Code Sql]

SELECT DISTINCT Sum(tblDetails.Cost) AS SumOfCost,
FROM tblStudyNo
INNER JOIN tblDetails
ON tblStudyNo.StudyProtocolNumber = tblDetails.StudyNo
INNER JOIN tblItem ON tblDetails.DetailNo = tblItem.DetailsNo
and(((tblStudyNo.StudyProtocolNumber)=[parameter1]) AND ((tblItem.Status)='in storage') AND ((tblDetails.Category)<>"Consumable"));

[/code]
 
YOu might get a better answer in an Access forum. this forum is for the database Microsoft SQl Server which uses a differnt syntax than Access.

Questions about posting. See faq183-874
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top