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;
All I want to make this procedure to insert the
allocated_time value into the table
Timesheet using the parameter
SUM(fld_allocated_time) from the table
Timesheet is smaller or equal to
fld_allocated_hours from the table
Project, otherwise show an error message and exit.
How can I do this? I think my procedure code is not even close to what I want to do.