I just want to send my request here - maybe someone can help. It works like a charm. Thanks for the help!
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[PS_Event_Insert] ( @UserID int, @AmenityID int, @DateFrom datetime, @DateTo datetime, @TimeFrom nvarchar(50), @TimeTo nvarchar(50), @Description nvarchar(max), @IsPrivate bit, @NumberOfPeople nvarchar(100), @Food bit, @StatusID int, @Notes nvarchar(500) = NULL, @EventID int OUTPUT ) AS declare @newdtfrom datetime = cast(@DateFrom + ' ' + @TimeFrom as datetime) declare @newdtto datetime = cast(@DateTo + ' ' + @TimeTo as datetime) DECLARE @RecCount int BEGIN SET @RecCount = ( select count(*) from [events] where (@newdtfrom >= cast([datefrom] + ' ' + [timefrom] as datetime) and @newdtfrom <= cast([dateto] + ' ' + [timeto] as datetime)) or (@newdtto > cast([datefrom] + ' ' + [timefrom] as datetime) and @newdtto <= cast([dateto] + ' ' + [timeto] as datetime)) or (@newdtfrom <= cast([datefrom] + ' ' + [timefrom] as datetime) and @newdtto >= cast([dateto] + ' ' + [timeto] as datetime)) AND [AmenityID] = @AmenityID AND [StatusID] = 5 ) IF (@RecCount = 0) BEGIN INSERT INTO [Events] ( [UserID], [AmenityID], [DateFrom], [DateTo], [TimeFrom], [TimeTo], [Description], [IsPrivate], [NumberOfPeople], [Food], [StatusID], [Notes] ) VALUES ( @UserID, @AmenityID, @DateFrom, @DateTo, @TimeFrom, @TimeTo, @Description, @IsPrivate, @NumberOfPeople, @Food, @StatusID, @Notes ) SET @EventID = SCOPE_IDENTITY() END ELSE BEGIN SET @EventID = -999 END END
source share