replace characters other than last four

Hello, I have a standard credit card number that I would like to  do a replace or something to put * for all characters except the last four.

So this:
1234567890123456 or 1234-5678-9123-4567 would become ************3456 or ************4567 respectively

How is that accomplished

UPDATE LMVR_GuestCard
SET CardNumber = ?????
WHERE GuestID = @GuestID
gogetsomeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

matrix_aashCommented:
update yourtable
  set yourfield = replace(yourfield, '4567', '3456' )
where yourfield like 'criteria'
0
hieloCommented:
try:
UPDATE LMVR_GuestCard
SET CardNumber = Left(CardNumber,LEN(CardNumber)-4) + '****'
WHERE GuestID = @GuestID
0
BrandonGalderisiCommented:
Something like this:

UPDATE LMVR_GuestCard
SET CardNumber = replicate('*, len(cardnumber)-4) + right(cardnumber,4)
WHERE GuestID = @GuestID

It accounts for the difference in length of various credit card types (amex, discover, visa/mc).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

gogetsomeAuthor Commented:
I was hoping to not have to actually know the creditcard number. Isnt there some character replace method that uses some sort of ltrim??

UPDATE LMVR_GuestCard
SET CardNumber = ?
FROM LMVR_GuestCard GC, LMVR_PropertyReservations PR
WHERE GC.GuestID = @GuestID
AND
PR.@ReservationId = @ReservationId
AND
GC.GuestID = PR.GuestID
0
hieloCommented:
>>I was hoping to not have to actually know the creditcard number.
You don't. I misread you question and put **** only on the last 4 characters, but the suggestion by BrandonGalderisi puts * on all EXCEPT the last four, regardless of the number.
0
gogetsomeAuthor Commented:
Exactly what I was after. Thank you!
0
BrandonGalderisiCommented:
Thanks for the support while I was AFK hielo!
0
hieloCommented:
>>Thanks for the support while I was AFK hielo!
Anytime.

BTW: Good job.
0
NagarajuGaragaCommented:
declare @cardNum nvarchar(25)
 set @cardNum ='1234-5678-9123-4567'
 select stuff(@cardNum,1,(len(@cardNum)-4),replicate('*',len(@cardNum)-4))
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.