2010-07-12 290 views
0
DELIMITER $$ 

DROP FUNCTION IF EXISTS `workplantype`.`FUN_STOCKINVENTRY_CHECK` $$ 
CREATE FUNCTION `workplantype`.`FUN_STOCKINVENTRY_CHECK` (
PONo1 VARCHAR(20), 
PartCode1 VARCHAR(45) 
) RETURNS bool 
BEGIN 
DECLARE diff bool; 
set diff=false; 
select if(Remaining_Quantity=0.00, true, false) as diff from tblstockinventory where PONo=PONo1 && PartCode=PartCode1; 
return diff; 
END $$ 

DELIMITER ; 

如何避免不允許從函數返回結果集mysql錯誤?不允許從函數mysql錯誤返回結果集?

回答

3
select if(Remaining_Quantity=0.00, true, false) into @diff 
from tblstockinventory 
where PONo=PONo1 AND PartCode=PartCode1; 

可以減少IF()來

select Remaining_Quantity=0.00 into @diff 

,並得到相同的結果

+1

+1您按秒打我給它。請注意'@ diff'只需要'diff',因爲它是一個聲明變量。 – Mike 2010-07-12 12:35:09

相關問題