2016-11-15 6 views
0
CREATE DEFINER=`root`@`localhost` PROCEDURE `test2`(in employeeId text) 
BEGIN 
set @SQLQuery =CONCAT("select groupId,eventId,scheduleId,description,events,eventType, 
scheduledDate,name,designation,image,skills,duration,status,attachmentPath, 
case when scheduledDate < now() and (select count(*) from event_request where 
event_id=eventId and employee_code='",employeeId,"')>0 then 1 
when scheduledDate < now() and (select count(*) from event_request where 
event_id=eventId and employee_code='",employeeId,"')=0 then 0 
else '' end as hasRequested ,(SELECT actual_attendance_status_id FROM TJU.event_attendees_mapping where 
scheduleId=event_schedule_id and employee_code='",employeeId,"') 
as attendingStatus, 
case 
when 
(select count(*) from event_attendees_mapping where 
event_schedule_id=scheduleId and employee_code='",employeeId,"')>0 then 1 
else 0 end as isMyEvent,meetingRoom from EventList_View ", "and 1=1"); 

select @SQLQuery; 

END 

これは私の動的従業員IDを渡しています。これは私がこのプロシージャコール( "TJU_741")を呼び出したときの動的クエリのプロシージャです。mysqlのselectクエリでcon-cat動的IDを取得する方法

その後、私のクエリはあなたがそれはTJU_741は「私のクエリは、従業員IDのためになるようにCONCATする方法を私に提案してくださいする必要がありながら、各社員コードが「この「」TJU_741」のようになっていることがわかります

ここ
select groupId,eventId,scheduleId,description,events,eventType, 
scheduledDate,name,designation,image,skills,duration,status,attachmentPath, 
case when scheduledDate < now() and (select count(*) from event_request where 
event_id=eventId and employee_code=''TJU_741'')>0 then 1 
when scheduledDate < now() and (select count(*) from event_request where 
event_id=eventId and employee_code=''TJU_741'')=0 then 0 
else '''' end as hasRequested ,(SELECT actual_attendance_status_id FROM TJU.event_attendees_mapping where 
scheduleId=event_schedule_id and employee_code=''TJU_741'') 
as attendingStatus, 
case 
when 
(select count(*) from event_attendees_mapping where 
event_schedule_id=scheduleId and employee_code=''TJU_741'')>0 then 1 
else 0 end as isMyEvent,meetingRoom from EventList_View and 1=1 

なり'TJU_741'

+0

'employeeId'列はすでに一重引用符でエスケープされているようですので、連結文字列内の一重引用符を削除する必要がありますか? –

答えて

1

あなたのクエリは次のようにする必要があります

$param1 = 10; 
$param2 = 'Max'; 

$query = "select column from table where column = ".$param1." and "'.$param2.'" and column = '1'"; 

注:文字列、日付、日時、列挙型などを単一引用符で囲む必要があります。ですから、一重引用符でバインドすることを忘れないでください。

関連する問題