繁体   English   中英

MySQL存储过程将执行,但条件不起作用

[英]MySQL stored procedure will execute but conditions not working

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

我认为可能是括号

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

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

它只是一个想法。 我可能错了

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM