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



hi all, i need ur help in preparing a sql which performs scd2, i mean i have a scd2 mapping i n..

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

Post New Answer

More Programming Languages AllOther Interview Questions

What language / script is used to validate web page

3 Answers  


what are the topics choosen for jam round for interviews

1 Answers  


what is the difference between rename and label

1 Answers   Satyam,


What is Negative testing?

1 Answers  


What is the merger sort principle and its time complexity.

1 Answers   Verifone,


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

1 Answers  


What are the compilers of JAVA and .NET Programming languages?

1 Answers   HCL, Microsoft,


Given: (x-2)(x+3)= 100; solve the equation for x using any programing language.

2 Answers   Amazon, Manhattan,


How do you initialize a static member of a class with return value of some function?

1 Answers   Yahoo,


How many types of list exist in the HTML

2 Answers  


Explain polymorphism. Provide an example.

1 Answers   Amazon,


in a VB application, where the data will be stored after manipulation? what is the syntax for that?

1 Answers   TCS,


Categories