Click here to Skip to main content
16,019,843 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have this SQL statement Which I'm getting a error when I try to execute.
VB
SELECT        COUNT(*) AS TotalRecords
FROM            Expenses
WHERE        ([YEAR](PostDate) = [YEAR](@MyDate)) AND (MONTH(PostDate) = MONTH(@MyDate))


I'm Using a VistaDB which has the same syntax has SQL. Any Help would be appreciated.

What I have tried:

SELECT        COUNT(*) AS TotalRecords
FROM            Expenses
WHERE        ([YEAR](PostDate) = [YEAR](@MyDate)) AND (MONTH(PostDate) = MONTH(@MyDate))
Posted
Updated 30-Mar-21 20:19pm
Comments
thatraja 30-Mar-21 13:23pm    
What's the error?
crmfghtr 30-Mar-21 13:39pm    
How do I add an Image to this Forum
thatraja 30-Mar-21 13:44pm    
Upload image into some image hosting website & include the link in your question.

OR

Simply you can update your question with Error message.
Patrice T 30-Mar-21 13:23pm    
And you plan to tell what is the problem ?
crmfghtr 30-Mar-21 13:44pm    
Error 509 Invalid or Incomplete Statement SELECT Line1, Column 1
Error 507 Expected Expression ) Line 1 Column 61

1 solution

Try:

SQL
SELECT COUNT(*) As [TotalRecords] --or "TotalRecords"
FROM Expenses
WHERE YEAR(PostDate) = YEAR(@MyDate) AND MONTH(PostDate) = MONTH(@MyDate)


See Date and Time Functions[^] :
- YEAR[^]
- MONTH[^]

[EDIT]
In case of troubles with aliases, please read this: Getting Started - What's New - Version 5.0[^]

Quote:
Parser Fix: Does not correctly parse certain 3-part column names like: [dbo].[MyTable].ColumnName
Parser Fix: SELECT improperly accepts other unquoted keywords as table or column alias and thus can fail to recognize the start of a new statement when an optional alias can follow if no semicolon is used to separate them.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900