Ошибка
Подзапрос возвратил более 1 значения. Это недопустимо, если подзапрос следует =,! =, <, <=,>,> = Или когда подзапрос используется в качестве выражения.
Номер ошибки: 512
Уровень серьезности ошибки: 16
Состояние ошибки: 1
Процедура ошибки: AddBookingSlots
Код:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[AddDoctorBookingSlots]
ON [dbo].[BookingDay]
AFTER INSERT AS
BEGIN
DECLARE @starttime AS DATETIME = (SELECT MyDateTime1 = CAST([Day] AS DATETIME) + CAST(DayFrom AS DATETIME)
FROM INSERTED)
DECLARE @endtime AS DATETIME = (SELECT MyDateTime1 = CAST([Day] AS DATETIME) + CAST(DayTo AS DATETIME)
FROM INSERTED)
DECLARE @waitingtime AS INT = (SELECT WaitingTime FROM INSERTED)
WHILE (@starttime <= @endtime)
BEGIN
INSERT INTO [dbo].[Booking] ([DoctorID], [Day], [Time], [Fees], [Valid],
[PatientPhone], [BookingDayID],[PatientName], [PatientEmail],
[NoShow], [PackageID], [IsFree],[IsEditable],
[Shift], [CancelledByDoctor],[CancelledByUser],
[UserId], [UpdatedBy])
VALUES ((SELECT DoctorID FROM INSERTED),
(SELECT [Day] FROM INSERTED),
(SELECT CONVERT(CHAR(5), @starttime, 108)),
(SELECT ExaminationFees FROM Doctor
WHERE DoctorID = (SELECT DoctorID FROM INSERTED)), 1, NULL,
(SELECT BookingDayID FROM INSERTED), NULL, NULL, 0,
(SELECT [SubscribtionPackage] FROM Doctor
WHERE DoctorID = (SELECT DoctorID FROM INSERTED)), 0, 0,
(SELECT [Shift] FROM INSERTED), 0, 0,
(SELECT UserId FROM INSERTED),
(SELECT UpdatedBy FROM INSERTED))
SET @starttime = DATEADD(minute, @waitingtime, @starttime)
END
END