我有两张桌子:
我有这个程序:
CREATE PROCEDURE sp_insert_allocated_time(p_project_id integer, p_allocated_time integer)
RETURNS void
AS
BEGIN
INSERT INTO dbo.Timesheet(fld_id, fld_project_id,fld_allocated_time)
from
(
SELECT p.fld_id, p.fld_allocated_hours t.fld_allocated_time
FROM dbo.Project p
INNER JOIN dbo.Timesheet t
ON p.fld_id=t.fld_id
where t.fld_project_id = p_project_id
)AS Alias
GROUP BY fld_id, fld_allocated_days, fld_allocated_time
having SUM(fld_allocated_time) < fld_allocated_hours;
END;
我想制作这个程序:
答案 0 :(得分:1)
您可以使用IF ... ELSE块来检查条件并根据条件的结果执行适当的操作。为此,您需要将SUM(fld_allocated_time)和fld_allocated_hours的结果存储到变量中,然后:
IF @sumResult <= @allocatedTime
BEGIN
--do some stuff
END
ELSE
BEGIN
--do some other stuff
END