Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.26 KB | None | 0 0
  1. USE [Nabeghlavi13.12.2018]
  2. GO
  3. /****** Object:  StoredProcedure [dbo].[VisitsSelect]    Script Date: 12/14/2018 4:57:43 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. ALTER PROC [dbo].[VisitsSelect]
  9. (  
  10.     @TimeGroupID int
  11.       ,@StuffID int
  12.       ,@DateStart date
  13.       ,@DateEnd datetime
  14.       ,@DepartmentName nvarchar(500)
  15.       ,@StuffGroupID INT
  16. )
  17. AS
  18. BEGIN
  19.  
  20. SET @DateEnd=DATEADD(MINUTE,60*24-1,@DateEnd)
  21.  
  22.     select
  23.         v.ID
  24.         ,v.InCount
  25.         ,1 as AllowedAccessNumbers
  26.         ,v.IndeviceID
  27.         ,v.RecordTime
  28.         ,v.StuffID
  29.         ,v.TimeGroupID
  30.         ,s.Name as StuffFullName
  31.         ,s.IdNumber as StuffIDNumber
  32.         ,s.Department as DepartmentName
  33.         ,t.Name as TimeGroupName
  34.         ,v.AlarmType
  35.         ,t.TimeStart as GstartTime
  36.         ,t.TimeEnd as GendTime
  37.     from Visits as v
  38.     left join [Stuff] as s
  39.     on s.ID = v.StuffID
  40.     left join TimeGroups as t
  41.     on v.TimeGroupID = t.ID
  42.     where
  43.         (@StuffID is null OR v.StuffID = @StuffID)
  44.         and
  45.         (@DateStart is null OR v.RecordTime >= @DateStart)
  46.         and
  47.         (@DateEnd is null OR v.RecordTime <= @DateEnd)
  48.         and
  49.         (len(@DepartmentName) < 3 OR s.Department like '%'+@DepartmentName+'%')
  50.         AND
  51.         (@TimeGroupID IS NULL OR v.TimeGroupID=@TimeGroupID)
  52.         AND
  53.         (@StuffGroupID IS NULL OR s.StufGroupID=@StuffGroupID)
  54.     order by v.RecordTime asc
  55.  
  56. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement