forked from aravindsuri/ADFTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusp_Load_dimStore.sql
More file actions
36 lines (28 loc) · 2.28 KB
/
usp_Load_dimStore.sql
File metadata and controls
36 lines (28 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
USE [WineStoreDW]
GO
/****** Object: StoredProcedure [dbo].[usp_Load_dimStore] Script Date: 01.02.2023 10:08:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE usp_Load_dimStore
AS
BEGIN
--Implements an Upsert logic for Type 1 dimensions
--In this case the StoreName is the field which is used to match the stage.Store with dimStore
MERGE [dbo].[dimStore] AS [Target]
USING ( SELECT StoreName,
StoreType,
Description
FROM [stage].[Store]
) AS [Source]
ON [Target].[StoreName] = [Source].[StoreName] --- specifies the condition
WHEN MATCHED THEN
UPDATE SET
[Target].[StoreType] = [Source].[StoreType],
[Target].[Description] = [Source].[Description],
[Target].[UpdatedDate] = getdate()
WHEN NOT MATCHED THEN
INSERT (StoreName, StoreType, Description, InsertedDate, UpdatedDate )
VALUES ([Source].[StoreName], [Source].[StoreType], [Source].[Description], getdate(), getdate() ); --INSERT STATEMENT
END