Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Syntax error in SQL Statement

Author  Topic 

krishnap
Starting Member

2 Posts

Posted - 2009-07-29 : 13:10:35
Hi,

I am trying to use sql view in Microsoft Access.

Below is my code..It gives error 3075..Syntax error and I am not able to find the error. I checked all the column names and I am not able to see error. Please help.

SELECT Budget.[Income Statement Account], Budget.[RC Description], Budget.Month, Budget.[Division Name], Budget.[RC Number],
CASE When (Month(Budget.Month)) = (Month(GETDATE())-1) Then Sum(Budget.[SumOfGL Budget]) END as PlanMTD,
CASE When Month([Budget.Month]) = (Month(GETDATE())-1) Then Sum(June.Amount) END as 'ActualMTD',
Sum(Budget.[SumOfGL Budget]) As PlanYTD, Sum(June.Amount) as ActualYTD
FROM Budget INNER JOIN June ON (Budget.[Division Name] = June.[Division Name]) AND (Budget.Month = June.Month) AND (Budget.[RC Description] = June.RC) AND (Budget.[Income Statement Account] = June.[Income Statement Account])
GROUP BY Budget.[Income Statement Account], Budget.[RC Description], Budget.Month, Budget.[Division Name], Budget.[RC Number];

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-07-29 : 19:14:16
[code]
-- change this --
CASE When Month([Budget.Month]) = (Month(GETDATE())-1) Then Sum(June.Amount) END as 'ActualMTD',
Sum(Budget.[SumOfGL Budget]) As PlanYTD,
Sum(June.Amount) as ActualYTD
[/code][code]
-- To this --
SUM (CASE When Month([Budget].[Month]) = (Month(GETDATE())-1) Then June.Amount ELSE 0 END) as ActualMTD,
SUM (CASE When Month([Budget].[Month]) = (Month(GETDATE())-1) Then [SumOfGL Budget] ELSE 0 END) as PlanYTD,
SUM (CASE When Month([Budget].[Month]) = (Month(GETDATE())-1) Then June.Amount ELSE 0 End) as ActualYTD
[/code]

this is assuming that [Budget].[Month] contains a valid date. if it is just a month, then don't use the month() funtion over it
Go to Top of Page
   

- Advertisement -