hi all,
i need ur help in preparing a sql which performs scd2, i
mean i have a scd2 mapping i need a sql which can give me
same result as scd2 mapping,
SRC table:
cust_no, loc
01 abc
02 xyz
TGT table:
pm_ky cust_no loc current_flag
1 01 abc Y
2 02 xyz Y
cust 1 has changed his loc to xyz then it loads into TGT
table as below,
pm_ky cust_no loc current_flag
1 01 abc N
2 02 xyz Y
3 01 xyz Y
i need sql to get the above result, hope got me question,
Any suggestion will be appreciate..
thanks,
Vinod
Answer / Manisha
To perform SCD2 (Type 2 Slowly Changing Dimensions) using SQL, you can create a script that uses the CASE statement to handle historical changes. Here's an example based on the given tables and data:nn```sqlnCREATE TABLE cust_his (cust_no INT PRIMARY KEY,n loc VARCHAR(50),n current_flag CHAR(1) DEFAULT 'Y',n effective_date DATE);nnINSERT INTO cust_his (cust_no, loc, current_flag, effective_date)nSELECT cust_no, loc, 'N' AS current_flag,n CURRENT_DATE FROM custnWHERE cust_no = (SELECT cust_no FROM cust_his WHERE cust_no = 1 AND current_flag = 'Y');nnUPDATE cust_his SET current_flag = 'Y', effective_date = CURRENT_DATE WHERE cust_no = 1 AND current_flag = 'N';nnINSERT INTO cust_his (cust_no, loc, current_flag, effective_date) VALUES (2, 'xyz', 'Y', CURRENT_DATE);nnSELECT * FROM cust_his;```
| Is This Answer Correct ? | 0 Yes | 0 No |
What language / script is used to validate web page
what are the topics choosen for jam round for interviews
what is the difference between rename and label
What is Negative testing?
What is the merger sort principle and its time complexity.
could u please also write an example of a code that involves instances from an abstract class just as u did for interfaces because u said it could also work which i really doubt. thanks
What are the compilers of JAVA and .NET Programming languages?
Given: (x-2)(x+3)= 100; solve the equation for x using any programing language.
How do you initialize a static member of a class with return value of some function?
How many types of list exist in the HTML
Explain polymorphism. Provide an example.
in a VB application, where the data will be stored after manipulation? what is the syntax for that?