Mssql elegant way to mask a character set
I would like to have a fixed number of characters, say 10 (xxxxxxxxxx), and the input can be some varchar let say (abcd). The required output in this case is xxxxxxabcd.
Is there any neat way to avoid looping for 10-len (abcd)?
change
This quest can be a duplicate if honored by the accepted answer, but not by asking the question. Otherwise, I will be able to find the existing question and will not create a duplicate.
+3
dllhell
source
to share
2 answers
The trick is to add a fixed pattern with input and then grab the most correct characters n
:
RIGHT('xxxxxxxxxx' + 'abcd', 10)
+4
mellamokb
source
to share
I've done something similar with SQL Server in the past. Hope it helps.
select SUBSTRING('000000', 1,6-LEN('ABCD')) + 'ABCD'
0
TEEKAY
source
to share