2013-12-22 106 views
0
CREATE TRIGGER hundert   
AFTER INSERT ON Leistung 
FOR EACH ROW MODE  DB2SQL 
WHEN(SELECT modulNR, SUM(Prozentanteil) AS summe  
FROM  Leistung  
GROUP BY modulNr  
HAVING SUM(prozentanteil) > 100) 
BEGIN  ATOMIC 
SIGNAL SQLSTATE '23506' 
SET MESSAGE_TEXT = ('The Sum is  bigger then 100'); 
END 

如何創建一個WHEN語句,如果我想說它有考試的所有「prozentanteil」如果和更大然後100?CREATE TRIGGER INSERT WHEN(條件)DB2後

回答

1

如果您查看手冊中CREATE TRIGGER語句的語法圖,您會看到WHEN子句需要一個返回布爾值的搜索條件。子查詢本身不能返回布爾值。您可能打算在那裏使用謂詞EXISTS

... 
WHEN EXISTS (SELECT ...) 
...