I am currently working on creating my first Data_warehouse using sql-server
I have a Date dimension
i want to populate it using SSIS it ha
Here is a function for iso_year, the logic behind it is that the thursday of the week from the parameter date determine the year:
CREATE FUNCTION [dbo].[f_isoyear]
(
@p_date datetime
)
RETURNS int
as
BEGIN
RETURN datepart(yy, dateadd(wk, datediff(d, 0, @p_date)/7, 3))
END
Here is a Connect item that requests a function to calculate ISO_YEAR.
DATEPART - ISO_YEAR for ISO_WEEK
In the workaround section you have this function that you can use.
CREATE FUNCTION [dbo].[ISOyear](@date DATETIME)
returns SMALLINT
AS
BEGIN
DECLARE @isoyear SMALLINT = CASE
WHEN Datepart(isowk, @date)=1
AND Month(@date)=12 THEN Year(@date)+1
WHEN Datepart(isowk, @date)=53
AND Month(@date)=1 THEN Year(@date)-1
WHEN Datepart(isowk, @date)=52
AND Month(@date)=1 THEN Year(@date)-1
ELSE Year(@date)
END;
RETURN @isoyear;
END;