如何在MySQL中的单引号中执行select Query

时间:2012-09-17 10:45:15

标签: mysql stored-procedures

set Q1= 'SELECT ID, EnquiryID, EnquiryDate, CompanyName, ContactPerson FROM EnquiryHeader WHERE ';
set Q1 = concat(Q1,RefID);
上面的查询RefID中的

是过程中的参数 和RefID值是'DelFlg = 0和EnquirySource = 3'

那么如何在MYSQL中执行Q1?

1 个答案:

答案 0 :(得分:0)

试试这个:

set @Q1 = CONCAT('SELECT ID, EnquiryID, EnquiryDate, CompanyName, ContactPerson FROM Syscon.EnquiryHeader WHERE ',RefID);

PREPARE makeQ FROM @Q1;
EXECUTE makeQ;
DEALLOCATE PREPARE makeQ;