473,385 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Subquery to calculate the YTD amount

30
Hi I am trying to calculate the YTD amount and I keep getting the following error "You tried to execute a query that does note include the specified expression 'Fiscal Year' as part of an aggregate function". Can you offer any assistance?

Expand|Select|Wrap|Line Numbers
  1. SELECT GetFiscalYear([InvoiceDate]) AS [Fiscal Year], fFiscalPeriod([InvoiceDate]) AS Period, DatePart("q",[invoicedate]) AS Quarter, DatePart("m",[invoicedate]) AS [Month], MonthName(DatePart("m",[invoicedate])) AS [Month Name], DatePart("y",[invoicedate]) AS [Day of Year], DatePart("d",[invoicedate]) AS [Day], DatePart("w",[invoicedate]) AS Weekday, WeekdayName(DatePart("w",[invoicedate])) AS [Weekday Name], DatePart("ww",[invoicedate]) AS Week, InvoiceDetails.BudgetCodeID, Sum(InvoiceDetails.Amount) AS SumOfAmount,
  2. (SELECT Sum(InvoiceDetails.amount) AS YTD                                
  3.    FROM Invoices AS Inv INNER JOIN InvoiceDetails AS InvD ON Inv.InvoiceID = InvD.InvoiceID   
  4.    WHERE Inv.InvoiceDate >= DateSerial(Year([Invoices].[InvoiceDate]),1,1)               
  5.      AND Inv.InvoiceDate < DateSerial(Year([Invoices].[InvoiceDate]),                    
  6.        Month([Invoices].[InvoiceDate]) + 1, 1)) AS YTDAmount
  7. FROM Invoices INNER JOIN InvoiceDetails ON Invoices.InvoiceID = InvoiceDetails.InvoiceID
  8. GROUP BY GetFiscalYear([InvoiceDate]), fFiscalPeriod([InvoiceDate]), DatePart("q",[invoicedate]), DatePart("m",[invoicedate]), MonthName(DatePart("m",[invoicedate])), DatePart("y",[invoicedate]), DatePart("d",[invoicedate]), DatePart("w",[invoicedate]), WeekdayName(DatePart("w",[invoicedate])), DatePart("ww",[invoicedate]), InvoiceDetails.BudgetCodeID;

Thank you,
Jul 28 '10 #1
0 1377

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: marcello stanley | last post by:
--Boundary_(ID_89yLhNmAybJBOhP/kmhVvw) Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7BIT Hello, I am a mySQL newbie here and have some problem defining the mySQL...
2
by: coryjflynn | last post by:
I am try to update the Gender field for all females of a database with about 15,000 records. So how I started was by searching baby girl names on the web and manipulated some of there lists to...
7
by: Andrew Mayo | last post by:
Here's a really weird one for any SQL Server gurus out there... We have observed (SQL Server 2000) scenarios where a stored procedure which (a) begins a transaction (b) inserts some rows into...
2
by: Edwin Pauli | last post by:
Hi, Yesterday i had upgrade my PostgreSQL server from version 7.2.4 to 7.4.1. There are troubles with a subquery after the upgrade. Here is the query: SELECT team_naam, team_id, wpim, (
3
by: mfr | last post by:
hi, I've following table: +----+-------------+----------+-------+-------+ | id | productName | provider | items | price | +----+-------------+----------+-------+-------+ | 1 | product x |...
2
by: martin77 | last post by:
Here is what I have for the code keep getting error on 'declare variables and assign address to object variables Dim strId As String, strPayment As String, curPayment As Currency ...
1
by: sqlDon | last post by:
I am looking for some suggestions for rewriting a subquery to be more efficient. Select * from A where A.col1+A.col2 in (Select A.col1+A.col2 from A where A.Col3 = 'TEST1' and A.Col4 = 'TEST2') ...
2
by: LordGoran | last post by:
I'm stumped with this one. I'm trying to recode an SQL statement written in Access that will work for MySQL (4.1.22). In Access it used a stored Query, I'd like to use a subquery to replace the...
9
by: brendanmcdonagh | last post by:
Hi, I am designing a project for my friend as I am just a week old baby to vb and want to implement what I've learnt so far. She wants to be able to put start time, end time and lunch for each...
6
by: doug | last post by:
I am loading some HTML into a lightbox div via AJAX. What I would like to do is load the HTML into the lightbox div (a scrollable one), then get the height of the content of the div (not the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.