1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
with sr (n)
as
(
select 0
union all
select n + 30 from sr where n < 30 * 47
),
plage (hm)
as
(
select cast(dateadd(minute, n , 0) as time(0))
from sr
),
horaire (id, jour, debut, fin)
as
(
select 1, 1, '0900', '1200'
union all
select 2, 1, '1400', '1800'
union all
select 3, 2, '0800', '1300'
union all
select 4, 3, '1030', '1230'
union all
select 5, 3, '1600', '1930'
union all
select 6, 4, '0900', '1200'
union all
select 7, 4, '1400', '1800'
union all
select 8, 5, '0900', '1200'
union all
select 9, 5, '1400', '1800'
),
horairepropre (id, jour, debut, fin)
as
(
select
id,
jour,
cast(dateadd(minute, cast(substring(debut, 3, 2) as int), dateadd(hour, cast(substring(debut, 1, 2) as int), 0)) as time(0)),
cast(dateadd(minute, cast(substring(fin, 3, 2) as int), dateadd(hour, cast(substring(fin, 1, 2) as int), 0)) as time(0))
from horaire
),
rdv (id, creneau)
as
(
select 1, cast('2020-05-21 15:00:00' as datetime2(0))
union all
select 1, cast('2020-05-21 15:30:00' as datetime2(0))
union all
select 1, cast('2020-05-22 09:30:00' as datetime2(0))
union all
select 1, cast('2020-05-22 11:00:00' as datetime2(0))
union all
select 1, cast('2020-05-22 15:30:00' as datetime2(0))
union all
select 1, cast('2020-05-22 16:00:00' as datetime2(0))
)
select p.hm dispo
from plage p
inner join horairepropre h on p.hm >= h.debut and p.hm < h.fin
where h.jour = datepart(weekday, '2020-05-22')
and p.hm not in (select cast(creneau as time(0)) from rdv where cast(creneau as date) = cast('2020-05-22' as date))
option (maxrecursion 47); |
Partager