Advertisement
WorkAkkaunt

Функция для нахождения временных интервалов

Jun 27th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.23 KB | None | 0 0
  1. USE [oktell_cc_temp]
  2. GO
  3. /****** Object:  UserDefinedFunction [dbo].[AddTimeIntervals]    Script Date: 28.06.2019 9:42:08 ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. -- =============================================
  9. -- Author:      <Author,,Name>
  10. -- Create date: <Create Date,,>
  11. -- Description: <Description,,>
  12. -- =============================================
  13. ALTER FUNCTION [dbo].[AddTimeIntervals] (@idTask uniqueidentifier, @idOperator uniqueidentifier, @state int, @dateStart datetime, @timeStart datetime, @dateTimeStop datetime) RETURNS
  14.     @returnTable TABLE(IdTask uniqueidentifier, IdOperator uniqueidentifier, [State] int, DateStart datetime, TimeStart datetime, DateTimeStop datetime, Interval nvarchar(20))
  15. AS
  16. BEGIN
  17.     DECLARE @Start time
  18.     DECLARE @End time
  19.  
  20.     SET @Start = @timeStart
  21.     SET @End = CAST(@dateTimeStop as time)
  22.  
  23.     INSERT INTO @returnTable
  24.     SELECT @idTask
  25.     ,@idOperator
  26.     ,@state
  27.     ,@dateStart
  28.     ,@timeStart
  29.     ,@dateTimeStop
  30.     ,[oktell_cc_temp].[dbo].[Time_Intervals_At_Day].Interval
  31.     FROM [oktell_cc_temp].[dbo].[Time_Intervals_At_Day]
  32.         WHERE (@Start >= TimeStart AND @Start <= TimeEnd)
  33.               OR (@End >= TimeStart AND @End <= TimeEnd)
  34.               OR (TimeStart >= @Start AND TimeEnd <= @End)
  35.  
  36.     RETURN;
  37. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement