hurtownie-danych-gr4/Kalendarz.sql
Bartosz Kozłowski 0935e7e0cd Prześlij pliki do ''
Skrypt generowania kalendarza hurtowni
2017-04-19 09:20:12 +00:00

25 lines
692 B
Transact-SQL

declare @StartDate date;
declare @EndDate date;
declare @DateCounter int;
set @StartDate = '1900-01-01'; -- min wartość daty w Claim 1900/01/01
set @EndDate = '2207-12-31'; -- max wartośc daty w Claim 2207/12/25
set @DateCounter=1;
declare @TempDate date;
set @TempDate=@StartDate;
While @TempDate<=@EndDate
Begin
INSERT into Calendar ([Date], [Year],[Month],[Day],[Qarter])
values (
@TempDate,
cast( DATENAME(yyyy, @TempDate) as varchar(4)),
cast( DATEPart(mm, @TempDate) as varchar(2)),
cast( DATEPart(dd, @TempDate) as varchar(2)),
cast( DATENAME(q, @TempDate) as varchar(2))
);
set @TempDate=DATEADD(d , @DateCounter, @TempDate);
End;