Solved

Aggregated Function from Access (First)

Posted on 2000-03-23
3
141 Views
Last Modified: 2010-05-02
Hi

I need to know what the same function in SQL server 7 is for (First) the Aggregated function for Access.

e.g.

SELECT dtYear,dtMonth,
Sum(dtSales.dtBulkValue) AS dtBulkValue,
Sum(dtSales.dtBulkVolume) AS dtBulkVolume,
First(dtSales.dtRepCode) AS dtRepCode,
First(dtSales.dtTradeChannel) AS dtTradeChannel
FROM tblCustomers INNER JOIN dtSales
0
Comment
Question by:Rab
[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
3 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2652256
you may be able to do it with something like this:
SELECT TOP 1 dtYear,dtMonth,Sum(dtSales.dtBulkValue) AS dtBulkValue,
Sum(dtSales.dtBulkVolume) AS dtBulkVolume
FROM tblCustomers
INNER JOIN dtSales
ORDER BY (whichever field you want the top value for)


0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 20 total points
ID: 2652367
azrasound: using TOP 1 like this will produce 0 or 1 rows at all, you need to modify (see below)
Rab: you need to use GROUP BY:

SELECT S.dtYear,S.dtMonth,
Sum(S.dtBulkValue) AS dtBulkValue,
Sum(S.dtBulkVolume) AS dtBulkVolume,
( SELECT TOP 1 SI.dtRepCode FROM dtSales SI WHERE SI.dtYear = S.dtYear AND SI.dtMonth = S.dtMonth) AS dtRepCode,
( SELECT TOP 1 dtTradeChannel FROM dtSales SI WHERE SI.dtYear = S.dtYear AND SI.dtMonth = S.dtMonth) AS dtTradeChannel
FROM tblCustomers C INNER JOIN dtSales S
GROUP BY S.dtYear, S.dtMonth

0
 

Author Comment

by:Rab
ID: 2652906
Hi angelIII
If I use the query as above the SQL query returns two more records that the
Access query. Why would this be.

query e.g.

SELECT dtYear,dtMonth,
Sum(dtSales.dtSingleValue) AS dtSingleValue,
Sum(dtSales.dtSingleVolume) AS dtSingleVolume,
Sum(dtSales.dtMultiValue) AS dtMultiValue,
Sum(dtSales.dtMultiVolume) AS dtMultiVolume,
Sum(dtSales.dtBulkValue) AS dtBulkValue,
Sum(dtSales.dtBulkVolume) AS dtBulkVolume,
( SELECT TOP 1 dtSales.dtRepCode FROM dtSales SI WHERE SI.dtYear = dtSales.dtYear AND dtSales.dtMonth = dtSales.dtMonth) AS dtRepCode,
( SELECT TOP 1 dtTradeChannel FROM dtSales SI WHERE SI.dtYear = dtSales.dtYear AND dtSales.dtMonth = dtSales.dtMonth) AS dtTradeChannel

FROM tblCustomers  INNER JOIN dtSales
ON tblCustomers.CustomerID=dtSales.dtCustomerID
WHERE CNumber = '1000022120' Or CNumber = '1000022130'
GROUP BY dtYear,dtMonth,dtRepCode,dtTradeChannel
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

695 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