Empezar un tema nuevo

Ejemplo de vista sql para devolver los fines de semana del año actual

Este ejempo es útil para cuando trabajamos con calendarios y queremos tener una vista que nos pinte sábados y domingo como festivos.


SELECT a.holyday 
from
(
select dateadd(dd,number,d) As holyday
from master..spt_values
cross apply (select cast (cast(year(getdate()) as varchar) + '0101' as datetime) as d) d
where type = 'p'
and year(dateadd(dd,number,d))=year(d)<span class="fr-marker" data-id="0" data-type="false" style="display: none; line-height: 0;"></span><span class="fr-marker" data-id="0" data-type="true" style="display: none; line-height: 0;"></span>
and DATEPART(dw,dateadd(dd,number,d)) in (6,7)
union
select dateadd(dd,number,d) As holyday
from master..spt_values
cross apply (select cast (cast(year(getdate()-1) as varchar) + '0101' as datetime) as d) d
where type = 'p'
and year(dateadd(dd,number,d))=year(d)
and DATEPART(dw,dateadd(dd,number,d)) in (6,7)
union
select dateadd(dd,number,d) As holyday
from master..spt_values
cross apply (select cast (cast(year(getdate()+1) as varchar) + '0101' as datetime) as d) d
where type = 'p'
and year(dateadd(dd,number,d))=year(d)
and DATEPART(dw,dateadd(dd,number,d)) in (6,7)) A


Iniciar sesión o Registrarse para publicar un comentario