add generate time script
This commit is contained in:
parent
6d72578228
commit
a4b79ed296
@ -22,6 +22,68 @@ CREATE TABLE dim_time (
|
|||||||
);
|
);
|
||||||
GO
|
GO
|
||||||
|
|
||||||
|
DROP PROCEDURE IF EXISTS [dbo].[sPopulateDimDates_v2]
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE PROCEDURE [dbo].[sPopulateDimDates_v2]
|
||||||
|
@FromDate DATE = '1950-01-01',
|
||||||
|
@ToDate DATE = '2050-12-31'
|
||||||
|
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
DECLARE @DimDates TABLE
|
||||||
|
(
|
||||||
|
time_sk INTEGER identity(1,1) PRIMARY KEY,
|
||||||
|
time_bk DATE NOT NULL,
|
||||||
|
time_string NCHAR(10) NOT NULL,
|
||||||
|
year INTEGER,
|
||||||
|
month INTEGER,
|
||||||
|
day INTEGER,
|
||||||
|
quarter INTEGER
|
||||||
|
);
|
||||||
|
|
||||||
|
--Setting language
|
||||||
|
SET LANGUAGE English
|
||||||
|
|
||||||
|
--Populating Dimension
|
||||||
|
WHILE @FromDate <= @ToDate
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO @DimDates(
|
||||||
|
time_bk,
|
||||||
|
time_string,
|
||||||
|
year,
|
||||||
|
month,
|
||||||
|
day,
|
||||||
|
quarter
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
@FromDate as time_bk,
|
||||||
|
convert(nvarchar(10), @FromDate,20) AS time_string,
|
||||||
|
MONTH(@FromDate) AS [month],
|
||||||
|
YEAR(@FromDate) AS [year],
|
||||||
|
DAY(@FromDate) AS [day],
|
||||||
|
DATENAME(QUARTER,@FromDate) AS [quarter]
|
||||||
|
SET @FromDate = DATEADD(DAY, 1, @FromDate)
|
||||||
|
END
|
||||||
|
|
||||||
|
INSERT INTO dbo.dim_time(
|
||||||
|
time_bk,
|
||||||
|
time_string,
|
||||||
|
year,
|
||||||
|
month,
|
||||||
|
day,
|
||||||
|
quarter
|
||||||
|
)
|
||||||
|
SELECT time_bk, time_string, year, month, day,quarter
|
||||||
|
FROM @DimDates
|
||||||
|
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
EXEC [dbo].[sPopulateDimDates_v2]
|
||||||
|
GO
|
||||||
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS dim_drugs;
|
DROP TABLE IF EXISTS dim_drugs;
|
||||||
CREATE TABLE dim_drugs (
|
CREATE TABLE dim_drugs (
|
||||||
drug_sk INTEGER identity(1, 1) PRIMARY KEY,
|
drug_sk INTEGER identity(1, 1) PRIMARY KEY,
|
||||||
|
Loading…
Reference in New Issue
Block a user