Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    424
    Thanks
    8
    Thanked 6 Times in 6 Posts

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

    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

    Edit:
    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.
    Last edited by mOrloff; 07-08-2011 at 11:48 PM.
    ...because it's dundant already.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,720
    Thanks
    80
    Thanked 4,514 Times in 4,478 Posts
    Ready to kick yourself?

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

    Code:
    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..."

  • #3
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    Of course it also helps if you post in the correct forum. You posted a MSSQL question in the MySQL forum.

  • #4
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    424
    Thanks
    8
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by Old Pedant View Post
    Ready to kick yourself? ...
    I'm lacing up my big boots as we speak.

    Quote Originally Posted by Old Pedant View Post
    ... 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 ?????

    ~ Mo


    PS:
    Quote Originally Posted by guelphdad View Post
    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
    Last edited by mOrloff; 07-11-2011 at 02:52 PM.
    ...because it's dundant already.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •