MySQLで作成したストアドプロシージャの何が問題なのかを特定しようとしています。作成に問題はありませんでしたが、呼び出そうとしても機能しません。ワークベンチが表示しているエラーは
エラーコード:1064。SQL構文にエラーがあります。4行目の「SELECTApplicantID、LastName、FirstName、Mid」の近くで使用する正しい構文については、MySQLサーバーのバージョンに対応するマニュアルを確認してください。
そして、これが私のストアドプロシージャです。
-- --------------------------------------------------------------------------------
-- 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
結果の文字列/クエリをコピーして別のウィンドウで実行し、変数の適切な値を置き換えてみましたが、機能しています。
私はこのストアドプロシージャで立ち往生しています。あなたが私を助けてくれることを願っています。ありがとう!