Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.70 KB | None | 0 0
  1. DECLARE @dateExists bit = 0
  2. if exists((select * from c_disp_form where id_form = 103 and id_turma = 1 and start_date >= '2018-12-13 00:00:00.000' and start_date <= '2018-12-13 23:00:00.000'))
  3. begin
  4.     DECLARE @tempStart DATETIME = (select MIN(start_date) from c_disp_form where id_form = 103 and id_turma = 1 and start_date >= '2018-12-13 00:00:00.000' and start_date <= '2018-12-13 23:00:00.000')
  5.     DECLARE @tempEnd DATETIME = (select MIN(end_date) from c_disp_form where id_form = 103 and id_turma = 1 and start_date >= '2018-12-13 00:00:00.000' and start_date <= '2018-12-13 23:00:00.000')
  6.     DECLARE @maxTempStart DATETIME = (select MAX(start_date) from c_disp_form where id_form = 103 and id_turma = 1 and start_date >= '2018-12-13 00:00:00.000' and start_date <= '2018-12-13 23:00:00.000')
  7.     DECLARE @maxTempEnd DATETIME = (select MAX(end_date) from c_disp_form where id_form = 103 and id_turma = 1 and start_date >= '2018-12-13 00:00:00.000' and start_date <= '2018-12-13 23:00:00.000')
  8.     if exists((select * from c_disp_form where id_form = 103 and id_turma = 1 and @tempStart <= '2018-12-13 21:00:00.000' and '2018-12-13 21:00:00.000' < @tempEnd and @tempEnd >= '2018-12-13 23:00:00.000'))
  9.     begin
  10.         set @dateExists =1
  11.         print 'entrei primeiro if'
  12.     end
  13.     else if exists((select * from c_disp_form where id_form = 103 and id_turma = 1 and @maxTempStart <= '2018-12-13 21:00:00.000' and '2018-12-13 21:00:00.000' < @maxTempEnd and @maxTempEnd >= '2018-12-13 23:00:00.000'))
  14.     begin
  15.         set @dateExists =1
  16.         print 'entrei segundo if'
  17.     end
  18. end
  19. Select @tempStart as tempstart, @tempEnd as tempend, @maxTempStart as maxtempstart, @maxTempEnd as maxtempend, @dateExists as existe
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement