2014-11-04 48 views
0

MySQL存储过程将执行,但条件不起作用。有人可以解决这个问题吗?MySQL存储过程将执行,但条件不起作用

空值不检查or条件。是否需要更换or

DELIMITER $$ 

CREATE DEFINER=`rebar`@`%` PROCEDURE `SearchInProgress`(
ClientID bigint, 
GCName varchar(250), 
TeamID int, 
USPMID Bigint, 
JobReceivedDate datetime, 
importanceID Bigint 
) 
begin 
select * from jobdetails 
where 
    (clientid = ClientID or ClientID = "") and 
    (GCName = GCName or GCName ="") and 
    (TeamID = TeamID or TeamID ="") and 
    (ReceivedDate = JobReceivedDate or JobReceivedDate = "") and 
    (ImportanceID = importanceID or importanceID = "") and 
    (JobID in (select jobid from JobCoordinatorDetails where USProjectManagerID = USPMID)); 
end 

回答

0

我认为这可能是支架

(clientid = ClientID or ClientID = "")可以写成这样

(clientid = ClientID) OR (ClientID = "")

其胡斯塔思想。我可能是错的

0
DELIMITER $$ 
DROP PROCEDURE if exists SearchInProgress $$ 

CREATE PROCEDURE `SearchInProgress`(
    aclientID bigint, 
    aGCName varchar(250), 
    aTeamID int, 
    aUSProjectManagerID bigint, 
    aReceivedDate datetime, 
    aImportanceID bigint 
) 
begin 
select * from jobdetails 
where 
    (clientid = aclientID or aclientID = '') and 
    (GCName = aGCName or aGCName = '') and 
    (TeamID = aTeamID or aTeamID = '') and 
    (ReceivedDate = aReceivedDate or aReceivedDate = '0000-00-00 00:00:00') and 
    (ImportanceID = aImportanceID or aImportanceID = '') and 
    (JobID in (select jobid 
       from JobCoordinatorDetails 
       where USProjectManagerID = aUSProjectManagerID) or aUSProjectManagerID = '') 
    ; 
end 

参数名称和列名称必须不同。我已经在参数名称前加上了a

将空日期时间值替换为'0000-00-00 00:00:00':https://dev.mysql.com/doc/refman/5.7/en/datetime.html