Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DECLARE @dateExists bit = 0
- 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'))
- begin
- 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')
- 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')
- 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')
- 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')
- 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'))
- begin
- set @dateExists =1
- print 'entrei primeiro if'
- end
- 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'))
- begin
- set @dateExists =1
- print 'entrei segundo if'
- end
- end
- 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