Files
budget-database/procedures/proc_UpdateHolidaysTable.sql
2022-07-15 15:37:20 -04:00

23 lines
518 B
Transact-SQL

use Leo
go
alter proc dbo.proc_UpdateHolidaysTable
as
if not exists(select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'HOLIDAYS')
create table dbo.HOLIDAYS(dt date primary key clustered, Holiday varchar(50))
declare @year int = 2019
while @year < year(getdate()) + 40
begin
insert into dbo.Holidays(dt, Holiday)
select fhol.dt, fhol.Holiday
from
dbo.tvf_GetHolidays(@year) fhol
left join dbo.Holidays tbh on fhol.dt = tbh.dt
where fhol.dt is null
set @year = @year + 1
end
go