Stored procedure to compare two columns from different tables and make the insert
CREATE PROCEDURE sp_insert_allocated_time @p_project_id INT, @p_allocated_time INT
AS

BEGIN

DECLARE @sum_alloc_time int, @alloc_hours int, @fld_id int

select @sum_alloc_time = SUM(fld_allocated_time)
from dbo.Timesheet
where fld_project_id = @p_project_id;

select @alloc_hours = p.fld_allocated_hours, @fld_id = p.fld_id
FROM dbo.Project p
INNER JOIN dbo.Timesheet t
ON p.fld_id=t.fld_id
where t.fld_project_id = @p_project_id;

IF @sum_alloc_time &lt;= @alloc_hours
BEGIN
BEGIN TRAN;
INSERT INTO dbo.Timesheet(fld_id, fld_project_id,fld_allocated_time)
VALUES (@fld_id, @p_project_id, @p_allocated_time);
COMMIT TRAN;
END;

END;