[Solved] SQL: Comparing DATE Field's Month To INTEGER param.

Discuss the database features
Post Reply
Joe129
Posts: 2
Joined: Thu Dec 07, 2017 1:01 pm

[Solved] SQL: Comparing DATE Field's Month To INTEGER param.

Post by Joe129 »

Hi,

Having tried to use Google searches to find out what's wrong with my simple WHERE statement, I would like to just ask you users of this forum what's wrong with it:

Code: Select all

SELECT "Customer"."Name", "Address_Line1", "Address_Line2", "Job"."Job_Date", "Job"."Job_Time", "Job"."Hours_Worked"
FROM "Customer", "Job"
WHERE MONTH("Job"."Job_Date") = VALUE(:month);
The Job_Date field's type is DATE.

I assume the input prompt would provide the Integer parameter "Month" as Text, yet having the expression VALUE(:month) in this statement is causing my query to fail, while it works with this expression replaced by an Integer constant and this statement also failed when I replaced VALUE(:month) with just a reference to this parameter in case it was already an Integer value.

Error message:
SQL Status: HY000
Error code: 1000

Syntax error in SQL statement
Last edited by Joe129 on Thu Dec 07, 2017 7:10 pm, edited 2 times in total.
Open Office Version: 5.4.3.2 (x64)
Operating System: Windows 8.1 (x64)
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: SQL: Comparing DATE Field's Month To INTEGER Parameter

Post by Villeroy »

MONTH("Date") returns an integer between 1 and 12
In this context (parsed SQL) there is no function named VALUE and it is not necessary. Any named parameter such as :month will be evaluated by the SQL parser that is built into Base.

Code: Select all

...
WHERE MONTH("Date") = :month
should simply work.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Joe129
Posts: 2
Joined: Thu Dec 07, 2017 1:01 pm

Re: SQL: Comparing DATE Field's Month To INTEGER Parameter

Post by Joe129 »

Thanks for helping me. I had tried that WHERE statement before posting this question but I received the same syntax error message, I've just realized this is because month can't be used as a variable name because its a reserved name.
Open Office Version: 5.4.3.2 (x64)
Operating System: Windows 8.1 (x64)
Post Reply