Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will create the SQL Script to create procedures to insert/ update data and p

ID: 3595342 • Letter: Y

Question

You will create the SQL Script to create procedures to insert/ update data and process a project delay - SP_ProcessProjectDelay: Given a project Id, this procedure finds if any max end date of any activity within the project is after the project’s projected end date. If this happens, the procedure will calculate how many days it is late (use DATEDIFF) and fines the project $100 for each day late it is late. In addition, the project table’s “projectedenddate” will be updated with the new end date and the “fundedbudget” will be updated with the original funded budget plus the fines per day late. o Parameters: projectId. Example: The Falcon Coaster has a ProjectId “AA01” has a projected end date of 6/30/2017. It has 2 activities: ActivityId: AA90 ActivityName: Build Coaster EndDate: 6/01/2017 ActivityId: AA91 ActivityName: Inspect Coster EndDate: 7/30/2017 Since Activity AA91 ends 30 days after the projected end date of the project, the project will have an additional $3,000 (30 X $100) added to the fundedbudget column’s original value. Also, the project’s new projected end date will be “7/30/17”

Explanation / Answer

No schema details and respective data is given , so no sample output is not given.

Below is the procedure:

Create PROCEDURE projects(

@projectid INT

)
AS
BEGIN
DECLARE @newdate date, @newbudget int

--EXPLANATION
--here we select the records with activity that have crossed project end date and compute new values to store in the variables

select @newdate=c.projected_end_date,@newbudget=(c.fundedbudget+(DATEDIFF(DAY, c.projected_end_date, b.end_date)*100))
from tbl a
join
(SELECT distinct activityid
FROM tbl WHERE projectid=@projectid) b
on a.activityid=b.activityid
join
(select projected_end_date
FROM tbl WHERE projectid=@projectid) c
on b.projectid=c.projectid
where b.end_date > c.projected_end_date

--EXPLANATION
--here we update the table with new values stored in the variables

update tbl set projectedenddate= @newdate,fundedbudget=@newbudget where projectid=@projectid


END

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote