IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'spScheduleAppointmentPopulateSingle')
BEGIN
DROP Procedure spScheduleAppointmentPopulateSingle
END
--SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[spScheduleAppointmentPopulateSingle]
@CenterID int
AS
SET NOCOUNT ON
SET IDENTITY_INSERT ScheduleAppointment ON
INSERT INTO ScheduleAppointment
(
ScheduleAppointmentID
,ScheduleRoomID
,ScheduleAppointmentTypeCode
,PopulationTaskID
,StartTime
,DurationMinutes
,AgentID
,Transportation
)
SELECT
a.AppointmentID
,acra.AssessmentCenterRoomID
,at.Type
,a.PopulationTaskID
,DateStartTime
,datediff(mi, a.DateStartTime, a.DateEndTime)
,a.AgentID
,Transportation
FROM Appointment a
INNER JOIN AssessmentCenterRoomAppt acra
ON a.AppointmentID=acra.AssessCenterRoomApptID
JOIN AppointmentType at
ON a.AppointmentTypeID = at.AppointmentTypeID
INNER JOIN AssessmentCenterRoom acr ON acr.assessmentCenterRoomID=acra.AssessmentCenterRoomID
WHERE acr.AssessmentCenterID=@CenterID
SET IDENTITY_INSERT ScheduleAppointment OFF
|