SCD Type 2 implementation (Without Merge Statement)

Slowly changing dimensions or SCD are the 




ALTER PROCEDURE Sp_Data_Updation_History (

	@Brand_ID INT
	,@Brand_Name VARCHAR(30)
	)
AS
BEGIN
	IF (
			@Brand_ID IN (
				SELECT brand_id
				FROM stg.brands
				)
			)
		UPDATE stg.brands
		SET Version = isnull(version, 0) + 1
			,Updation_Time = cast(GETDATE() AS TIME)
			,Updation_Date = GETDATE()
			,brand_name = @brand_name
		WHERE brand_id = @Brand_ID
	ELSE
		INSERT INTO stg.brands
		VALUES (
			@brand_id
			,@brand_name
			,1
			,cast(GETDATE() AS TIME)
			,GETDATE()
			)
END

0 Comments