I have two tables:
And I have this procedure:
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;
I want to make this procedure:
you can use IF...ELSE block to check the condition and do appropriate action based on the result of condition. for that you need to store the result of SUM(fld_allocated_time) and fld_allocated_hours into variables and then:
IF @sumResult <= @allocatedTime
BEGIN
--do some stuff
END
ELSE
BEGIN
--do some other stuff
END
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.