add dates

This commit is contained in:
Justyna Lipska 2016-05-16 21:13:03 +02:00
parent 5a4fb5900c
commit 91eabafaff

33
dates.sql Normal file
View File

@ -0,0 +1,33 @@
drop table Data;
CREATE TABLE Data (
id int PRIMARY KEY IDENTITY(1,1),
data date NOT NULL,
datastring char(10) NOT NULL,
rok char(4) NOT NULL,
miesiac char(2) NOT NULL,
dzien char (2) NOT NULL,
miesiacNazwa varchar(16) NOT NULL,
dzienTygodniaNazwa varchar(16) NOT NULL,
kwartal char(1) NOT NULL
);
CREATE TABLE Data0 (
id int PRIMARY KEY IDENTITY(1,1),
data date NOT NULL)
declare @startDate Date;
declare @endDate Date;
declare @offset Date;
select @startDate = '1999/01/01';
select @endDate = '2111/01/01';
select @offset = @startDate;
while @offset < @endDate begin
insert into data(data, datastring, rok, miesiac, dzien, miesiacNazwa, dzienTygodniaNazwa, kwartal)
values(@offset, CONVERT(varchar, @offset, 105), YEAR(@offset), MONTH(@offset), DAY(@offset), DATENAME(month, @offset), DATENAME(weekday, @offset), DATENAME(q, @offset) );
select @offset = dateadd(day, 1, @offset);
print @offset;
end
select * from data