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

  • Home
  • SEARCH
  • 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 9157889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:07:35+00:00 2026-06-17T13:07:35+00:00

I’ve been trying to determine what’s the problem with the stored procedure that I

  • 0

I’ve been trying to determine what’s the problem with the stored procedure that I made in MySQL. I’ve had no problems in creating it but it’s not working when I am trying to call it. The error that the Workbench is displaying 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 ‘SELECT ApplicantID, LastName, FirstName, Mid’ at
line 4.

And here is my stored procedure,

-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$

CREATE DEFINER=`pinpoint_kevin`@`%` PROCEDURE `usp_Processing_GetApplicantByJobPostIDandStatus`(
    IN _ApplicationStatus VARCHAR(100),
    IN _JobPostID VARCHAR(64),
    IN _startRowIndex INT,
    IN _maximumRows INT,
    IN _Order NVARCHAR(20))
BEGIN
    DECLARE _OuterSelectString VARCHAR(1000);
    DECLARE _OuterFromString1 VARCHAR(1000);
    DECLARE _OuterFromString2 VARCHAR(1000);
    DECLARE _InnerSelectString VARCHAR(2000);
    DECLARE _InnerFromString VARCHAR(1000);
    DECLARE _InnerWhereString VARCHAR(1000);
    DECLARE _InnerOrderByString VARCHAR(1000);
    DECLARE _OuterWhereString VARCHAR(1000);
    DECLARE _ProcessingStepID VARCHAR(64);
    DECLARE _ApplicationProcessingID VARCHAR(64);
    DECLARE _YEHEY TEXT;

    SELECT
        ProcessingStepID
    INTO
        _ProcessingStepID
    FROM
        ProcessingStep
    WHERE
        ProcessingStepName = _ApplicationStatus;

    SELECT
        ApplicationProcessingID
    INTO
        _ApplicationProcessingID
    FROM
        ApplicationProcessing AS AP
            INNER JOIN
        ProcessingStep AS PS ON AP.ProcessingStepID = PS.ProcessingStepID
    WHERE
        PS.ProcessingStepName = _ApplicationStatus
    ORDER BY
        AP.TransactionDate
    LIMIT
        1;

    SET
        _OuterSelectString = '
                                SET
                                    @row_num = 0;

                                SELECT
                                    ApplicantID,
                                    LastName,
                                    FirstName,
                                    MiddleName,
                                    Email,
                                    ContactNumber,
                                    ApplicantCount,
                                    ApplicationNumber,
                                    ResumeStatus,
                                    LastTransactionDate,
                                    MovedBy,
                                    StepType,
                                    AdministeredBy,
                                    Evaluation,
                                    Recommendation,
                                    DateTaken,
                                    Mark,
                                    RowRank
                             ';
    SET
        _OuterFromString1 = 'FROM (
                            ';

    SET
        _InnerSelectString = 'SELECT 
                                (SELECT
                                    COUNT(*)
                                FROM
                                    Applicant_2 AS App 
                                        INNER JOIN
                                    ApplicantJobPost AS AJP ON App.ApplicantID = AJP.ApplicantID
                                        INNER JOIN
                                    ApplicationStatus AS APPS ON AJP.ApplicationStatusID = APPS.ApplicationStatusID
                                WHERE
                                    APPS.ApplicationStatusName = ?
                                        AND
                                    AJP.JobPostId = ? AND AJP.IsForwarded = 0) AS ApplicantCount,
                                    App.ApplicantID AS ApplicantID,
                                    App.LastName AS LastName,
                                    App.FirstName AS FirstName,
                                    App.MiddleName AS MiddleName,
                                    App.Email AS Email,
                                    App.BirthDate AS BirthDate,
                                    App.Address AS Address,
                                    App.ContactNumber AS ContactNumber,
                                    App.FileName  AS FileName,
                                    App.FileExtension AS FileExtension,
                                    App.DateCreated AS DateCreated,
                                    AJP.ApplicationNumber AS ApplicationNumber,
                                    AJP.IsReadResume AS ResumeStatus,
                                    AP.TransactionDate AS LastTransactionDate,
                                    AP.MovedBy AS MovedBy,
                                    AP.ProcessingStepType AS StepType,
                                    AP.AdministeredBy AS AdministeredBy,
                                    AP.Evaluation AS Evaluation,
                                    AP.Recommendation AS Recommendation,
                                    AP.DateTaken AS DateTaken,
                                    AJP.Mark AS Mark,
                                    @row_num := @row_num + 1 AS RowRank 
                                    ';

    SET
        _InnerFromString = 'FROM
                                Applicant_2 AS App 
                                    INNER JOIN
                                ApplicantJobPost AS AJP ON App.ApplicantID = AJP.ApplicantID
                                    INNER JOIN
                                ApplicationStatus AS APPS ON AJP.ApplicationStatusID = APPS.ApplicationStatusID
                                    INNER JOIN
                                ApplicationProcessing AS AP ON AP.ApplicantJobPostID = AJP.ApplicantJobPostID
                            ';

    SET
        _InnerWhereString = 'WHERE
                                APPS.ApplicationStatusName = ?
                                    AND
                                AJP.JobPostId = ?
                                    AND
                                AP.ProcessingStepID = ?
                                    AND
                                AJP.IsForwarded = 0
                            ';

    IF (_ApplicationStatus = 'Exam' OR _ApplicationStatus = 'Interview')
    THEN
        SET _InnerWhereString = 'WHERE
                                APPS.ApplicationStatusName = ?
                                    AND
                                AJP.JobPostId = ?
                                    AND
                                AP.ProcessingStepID = ?
                                    AND
                                AJP.IsForwarded = 0
                                    AND
                                AP.ApplicationProcessingID = ? ';
    END IF;

    SET
        _OuterFromString2 = ') AS WithRowNumbers
                            ';

    SET
        _OuterWhereString = 'WHERE
                                RowRank > _startRowIndex AND RowRank <= (_startRowIndex + _maximumRows)
                            ';

    IF (_Order = 'Transaction')
    THEN
        SET
            _InnerOrderByString = 'ORDER BY 
                                        AP.TransactionDate,
                                        LastName,
                                        IsReadResume,
                                        Mark,
                                        DateTaken DESC
                                  ';

    ELSEIF (_Order = 'TransactionDesc')
    THEN
        SET
            _InnerOrderByString = 'ORDER BY
                                        AP.TransactionDate DESC,
                                        LastName,
                                        IsReadResume,
                                        Mark,
                                        DateTaken DESC
                                  ';

    ELSEIF (_Order = 'Last NameDesc')
    THEN
        SET
            _InnerOrderByString = 'ORDER BY
                                        LastName DESC,
                                        IsReadResume,
                                        Mark,
                                        AP.TransactionDate DESC,
                                        DateTaken DESC
                                  ';

    ELSEIF (_Order = 'Last Name')
    THEN
        SET
            _InnerOrderByString = 'ORDER BY
                                        LastName,
                                        IsReadResume,
                                        Mark,
                                        AP.TransactionDate DESC,
                                        DateTaken DESC
                                  ';

    ELSEIF (_Order = 'Resume StatusDesc')
    THEN
        SET
            _InnerOrderByString = 'ORDER BY
                                        IsReadResume DESC,
                                        Mark,
                                        AP.TransactionDate DESC,
                                        LastName,
                                        DateTaken DESC
                                  ';

    ELSEIF (_Order = 'Resume Status')
    THEN
        SET
            _InnerOrderByString = 'ORDER BY
                                        IsReadResume,
                                        Mark,
                                        AP.TransactionDate DESC,
                                        LastName,
                                        DateTaken DESC
                                  ';
    END IF;

    SET _YEHEY = CONCAT(_OuterSelectString, _OuterFromString1, _InnerSelectString, _InnerFromString, _InnerWhereString, _OuterFromString2, _OuterWhereString);
    SET @WholeQuery = _YEHEY;
    PREPARE statement FROM @WholeQuery;
    SET @a = _ApplicationStatus;
    SET @b = _JobPostID;
    SET @c = _ApplicationStatus;
    SET @d = _JobPostID;
    SET @e = _ProcessingStepID;

    IF (_ApplicationStatus = 'Exam' OR _ApplicationStatus = 'Interview')
    THEN
        SET @f = _ApplicationProcessingID;
        EXECUTE statement USING @a, @b, @c, @d, @e, @f;

    ELSE
        EXECUTE statement USING @a, @b, @c, @d, @e;
    END IF;

    DEALLOCATE PREPARE statement;

    SELECT _YEHEY;
    SELECT @WholeQuery;

END

I’ve already tried copying the resulting string/query and run it in another window and replaced the appropriate values for the variables and it’s working.

I’m stuck with this stored procedure. I hope you could help me. 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-06-17T13:07:36+00:00Added an answer on June 17, 2026 at 1:07 pm

    As documented under SQL Syntax for Prepared Statements:

    SQL syntax for prepared statements does not support multi-statements (that is, multiple statements within a single string separated by “;” characters).

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I have been unable to fix a problem with Java Unicode and encoding. The
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.