Home > Blockchain >  SQL query for 'The account number is masked by an asterisk(*) except for the last 4 digits in b
SQL query for 'The account number is masked by an asterisk(*) except for the last 4 digits in b

Time:12-22

table

ACC_NO      pre_val    New_val
123489432   123489432  123489435
123489532   123489532  123489435

I asked some of my friends but not getting how to write the sql query.

CodePudding user response:

Your question is a bit unclear but, I guess you want something like that(?)

 SELECT LPAD(LEFT(ACC_NO, 4),9, "*");

CodePudding user response:

Extract the last 4 digits with RIGHT() and concatenate them with the asterisks that replace the first 5 digits.

SELECT ACC_NO, CONCAT('*****', RIGHT(pre_val, 4)) AS pre_val, CONCAT('*****', RIGHT(new_val, 4)) AS new_val
FROM yourTable
  • Related