PDA

View Full Version : Update Help Needed: How do I keep only the last four characters


mOrloff
07-08-2011, 11:20 PM
I've got to clean up a credit card number column.
Is there a MS SQL function that would allow me to update all the values in that column to only have whatever the last 4 chars are?
I looked at some oc the TRIM and LENGTH functions, but trim seemed to be focused on trimming whitespace, and I'm not quite sure how to make length useful here.

Can someone please point the way?
~ Mo


Well, the new plan to just erase all the CC data has now landed on my desk, so I don't need an answer anymore, but I am still interested in how people would do this.

Old Pedant
07-09-2011, 12:21 AM
Ready to kick yourself?

http://dev.mysql.com/doc/refman/5.5/en/functions.html
http://dev.mysql.com/doc/refman/5.5/en/string-functions.html
http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_right


UPDATE table SET column = RIGHT( TRIM( column ), 4 )

Take some time to peruse all the useful functions that MySQL has to offer. Read through all of Chapter 11 at least one time. You won't remember the details, but you'll remember "Oh, yeah, there's a function that will..."

guelphdad
07-09-2011, 02:59 AM
Of course it also helps if you post in the correct forum. You posted a MSSQL question in the MySQL forum.

mOrloff
07-11-2011, 02:44 PM
Ready to kick yourself? ...
I'm lacing up my big boots as we speak.

... Read through all of Chapter 11 at least one time. You won't remember the details, but you'll remember "Oh, yeah, there's a function that will..."
Good point.
I am definitely adding that to my to-do list.
Now ... where did I put my to-do list ????? :D

~ Mo


PS:
Of course it also helps if you post in the correct forum. You posted a MSSQL question in the MySQL forum.
Hmm, yeah, sorry for that :)