Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6609225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:41:35+00:00 2026-05-25T19:41:35+00:00

I have a simple table that has two columns: an auto-increment int column called

  • 0

I have a simple table that has two columns: an auto-increment int column called id and a date column called start. I’m trying to write a stored procedure that, given a value, will calculate the appropriate record to tie it to. The problem is that I’m getting a syntax error that doesn’t really tell me what’s going on. The error is:

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘SET finalResult = candidate;

Here is the code I’m using to create the procedure. Can anyone please tell me what I’m doing wrong?

delimiter //
CREATE PROCEDURE FindGCLDate(IN targetDate DATE)
    BEGIN
        DECLARE candidate DATE;
        DECLARE finalResult DATE;
        DECLARE loopComplete BOOLEAN;
        DECLARE allDates CURSOR FOR SELECT * FROM gcl_dates;
        DECLARE CONTINUE HANDLER FOR NOT FOUND
            SET loopComplete = TRUE;

        OPEN allDates;

        myLoop : LOOP
            FETCH allDates INTO candidate;
            SELECT candidate;
            IF targetDate < candidate
                SET finalResult = candidate;  -- this is the offending line
                SET loopComplete = TRUE;
            END IF;

            IF loopComplete THEN
                CLOSE allDates;
                LEAVE myLoop;
            END IF;
        END LOOP myLoop;

        SELECT finalResult;
    END //

I know there is more wrong with the procedure — I haven’t defined an out parameter or returned anything yet. But I’m just wondering why I am getting this error.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:41:35+00:00Added an answer on May 25, 2026 at 7:41 pm

    You’re missing a THEN on the line above it:

    IF targetDate < candidate
    

    should be

    IF targetDate < candidate THEN
    

    From the fine manual, the syntax for an IF statement is this:

    IF search_condition THEN statement_list
        [ELSEIF search_condition THEN statement_list] ...
        [ELSE statement_list]
    END IF
    

    where optional things are, as usual, marked with brackets; there are not brackets around THEN so it is required.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple cakephp app with table articles that has a cat_id column
If I have a table that (among other columns) has two DATETIME columns, how
Lets say I have a simple table that only contains two columns: MailingListUser -
I have an oracle table that has a column called system_access that has the
I have a simple table (lets call it Table1) that has a NVARCHAR field
I have two simple tables in my database. A card table that contains Id,
I'm trying to have a simple html table, that highlights a row as a
I have a simple table made up of two columns: col_A and col_B .
I have a simple data logging table with two data columns A and B
I have a table that has a column that contains links. Each cell in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.