forked from aravindsuri/ADFTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusp_Load_dimCurrency.sql
More file actions
34 lines (27 loc) · 2.12 KB
/
usp_Load_dimCurrency.sql
File metadata and controls
34 lines (27 loc) · 2.12 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
USE [WineStoreDW]
GO
/****** Object: StoredProcedure [dbo].[usp_Load_dimCurrency] Script Date: 01.02.2023 10:08:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[usp_Load_dimCurrency]
AS
BEGIN
--Implements an Upsert logic for Type 1 dimensions
--In this case the CurrencyCode is the field which is used to match the stage.Currency with dimCurrency
MERGE [dbo].[dimCurrency] AS [Target]
USING ( SELECT CurrencyCode,
CurrencyName
FROM [stage].[Currency]
) AS [Source]
ON [Target].[CurrencyCode] = [Source].[CurrencyCode] --- specifies the condition
WHEN MATCHED THEN
UPDATE SET
[Target].[CurrencyName] = [Source].[CurrencyName],
[Target].[UpdatedDate] = getdate()
WHEN NOT MATCHED THEN
INSERT (CurrencyCode, CurrencyName, InsertedDate, UpdatedDate )
VALUES ([Source].[CurrencyCode], [Source].[CurrencyName], getdate(), getdate() ); --INSERT STATEMENT
END
GO