Forum Discussion

TheTallman's avatar
TheTallman
Copper Contributor
Feb 25, 2022

Need a query for updating records to retain existing keys based on certain condition in sql table.

Hi, I need sql query to perform below task.
We have one retailer table has demographic information of retailers like ..

 

 

And as RETAILER_KEY is BIGINT identity column and we want to keep this column values static for same retailer in this way

Data is inserting in this table in this way to keep same RETAILER_KEY for same person where demographic information is same. so if any new retailer information is coming in system, then new RETAILER_ID get assigned to that person but if new person has shared same demographic information on RETAILER_NAME, RETAILER_DOB, RETAILER_GENDER then logic assign a same RETAILER_KEY to new record which is already assigned to all same persons (RETAILER_NAME, RETAILER_DOB, RETAILER_GENDER). but noticed some records in table where RETAILER_KEY didn't assign correctly and logic assign new key to person instead of existing key.

Here is example ..

 

 

The highlighted records below have the same name, DOB and gender yet they have different RETAILER keys. This is not correct.

Sr No 4, must have 10001 RETAILER_KEY assigned as he is a same man like Sr No 1,2 but logic assigned new 20001 that is not correct.

they should be like this in table

 

so can you pls give an script to check all those records and update existing RETAILER_KEY to all those person have the same name, DOB and gender.

 

Resources