Subquery

G

Guest

I need HELP :(

I have a query with a subquery that is giving me an error message.
I am trying to sum the sales from years and months before the actual.
I have tried Dsum, but it is too slow.

Can any one help me??? Please!

This is my query:
SELECT qry_Rslts_SalesForecasting.IdPrdctByCmpny,
qry_Rslts_SalesForecasting.Year, qry_Rslts_SalesForecasting.Month,
CDate(DateSerial([Year],[Month],1)) AS [Date],
qry_Rslts_SalesForecasting.SalesQuantity AS QuantitySales, (Select
sum(SalesQuantity) as SUMA From qry_Rslts_SalesForecasting2 where
qry_Rslts_SalesForecasting2.Date>qry_Rslts_SalesForecasting.Date) AS Calculo
FROM qry_Rslts_SalesForecasting
GROUP BY qry_Rslts_SalesForecasting.IdPrdctByCmpny,
qry_Rslts_SalesForecasting.Year, qry_Rslts_SalesForecasting.Month,
qry_Rslts_SalesForecasting.SalesQuantity, (Select sum(SalesQuantity) as SUMA
From qry_Rslts_SalesForecasting2 where
qry_Rslts_SalesForecasting2.Date>qry_Rslts_SalesForecasting.Date)
ORDER BY qry_Rslts_SalesForecasting.Year, qry_Rslts_SalesForecasting.Month;
 
A

Amy Blankenship

Your query is far enough away from the syntax it needs that I can't see
exactly where you're going. I suspect that you need a join relating
SalesForecasting and SalesForecasting2. You can't have a subselect in the
select clause because the subselect is essentially returning a table even if
you've only specified one field and you think you've fined it down to only
one row. Have you tried using the query builder for this?

HTH;

Amy
 
J

John Spencer

What is the error message?
Do you have two queries qry_Rslts_SalesForecasting and
qry_Rslts_SalesForecasting2? Or are you trying to reference
qry_Rslts_SalesForecasting2 as a second instance of
qry_Rslts_SalesForecasting?

Might I suggest you post the query with DSUM that is too slow. It may help
to clear up the confusion.
 
G

Guest

I do have two queries qry_Rslts_SalesForecasting and
qry_Rslts_SalesForecasting2.

I resolved my problem with a subquery. My problem was that I was grouping at
the end of the query...

Thanks a lot, all, for your time!

John Spencer said:
What is the error message?
Do you have two queries qry_Rslts_SalesForecasting and
qry_Rslts_SalesForecasting2? Or are you trying to reference
qry_Rslts_SalesForecasting2 as a second instance of
qry_Rslts_SalesForecasting?

Might I suggest you post the query with DSUM that is too slow. It may help
to clear up the confusion.


Lina Manjarres said:
I need HELP :(

I have a query with a subquery that is giving me an error message.
I am trying to sum the sales from years and months before the actual.
I have tried Dsum, but it is too slow.

Can any one help me??? Please!

This is my query:
SELECT qry_Rslts_SalesForecasting.IdPrdctByCmpny,
qry_Rslts_SalesForecasting.Year, qry_Rslts_SalesForecasting.Month,
CDate(DateSerial([Year],[Month],1)) AS [Date],
qry_Rslts_SalesForecasting.SalesQuantity AS QuantitySales, (Select
sum(SalesQuantity) as SUMA From qry_Rslts_SalesForecasting2 where
qry_Rslts_SalesForecasting2.Date>qry_Rslts_SalesForecasting.Date) AS
Calculo
FROM qry_Rslts_SalesForecasting
GROUP BY qry_Rslts_SalesForecasting.IdPrdctByCmpny,
qry_Rslts_SalesForecasting.Year, qry_Rslts_SalesForecasting.Month,
qry_Rslts_SalesForecasting.SalesQuantity, (Select sum(SalesQuantity) as
SUMA
From qry_Rslts_SalesForecasting2 where
qry_Rslts_SalesForecasting2.Date>qry_Rslts_SalesForecasting.Date)
ORDER BY qry_Rslts_SalesForecasting.Year,
qry_Rslts_SalesForecasting.Month;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Problem with SQL query 1
Year to Date subquery 3
subquery help 1
Subquery 6
Subquery 3
SubQuery Assistance... 1
Help with a subquery 5
dsum sytax error 5

Top