Remove trailing characters (and a small rant)

Often when coding I’ll search for a snippet of code to avoid reinventing the wheel. Code re-use is good, right?

From now on, whenever a search like that ends up sending me over to experts-exchange.com (which is a signup, members only site that shows the question text for all to see but masks the answers to entice people to sign up) I’m going to make an effort to write up a free version of  the answer here.

I really dislike that site, because all hits from there are a complete waste of time for a non member. I’d love to hear from anyone who has a membership as to what sort of quality answers are hiding behind those obfuscation layers. It’d be nice if google would let you create a list of ‘never show results from these sites’ to my account settings – it’d be a lot quicker than having to append ‘-site:experts-exchange.com’ all the time. Maybe their new Custom Search Engine offering could go some way to filling that void, however I digress.

 

Anyway, here’s a quick piece of SQL allowing you to update a table to remove trailing commas. It’s easily adaptable to replace other characters, or to remove leading characters as well.

update Location set Suburb = left(Suburb,len(Suburb)-1) where Right(Suburb,1) = ','

Not a complex piece of SQL by any means, but if it saves someone 5 minutes then job done.

Tags:
Posted on Wednesday, July 09, 2008 2:50 PM | Miscellaneous SQL

Like this? Share it!

  • # re: Remove trailing characters (and a small rant)
    Gravatar
    Commented on 7/9/2008 3:26 PM

    I've been wanting the same feature for exactly the same site (and a few others).

    [)amien

  • # re: Remove trailing characters (and a small rant)
    Gravatar
    Commented on 7/9/2008 4:42 PM

    Hi Damien,

    Wow that's really weird - I was just reading your blog about 10 minutes ago..

    I just started having a look at the google custom search product. It looks like it has potential, however it works on a whitelist rather than a blacklist. Need a bit more time to explore it fully.

    If it's not there I might end up writing something. You'd think it would be a fairly common request though..

    Ross

  • # re: Remove trailing characters (and a small rant)
    Gravatar
    Commented on 7/14/2008 1:39 PM

    Interestingly I have a friend who belongs to Experts Exchange as a PAID member (about $10/Month from memory). Now he's a paid member because it means his queries get answered very quickly - on the day we met for lunch he'd asked for a regex before hand and it was done when he got back to the office. Nice.

    As an aside (I don't know if this is because I have js disabled by default) but I can always see the answers on Experts Exchange if I scroll down far enough (past all the ads and junk). Is this just me?


    Andy.

  • # re: Remove trailing characters (and a small rant)
    Gravatar
    Commented on 7/14/2008 4:54 PM

    Hey Andy,

    Yeah Sam pointed that out to me too - he's been pulling the results from google's cache to get the same effect. It's interesting to know that your friend rates Experts Exchange though - maybe I was a bit hasty to jump to conclusions about their content!

  • # re: Remove trailing characters (and a small rant)
    Gravatar
    Commented on 7/19/2008 6:48 PM

    Hi Ross

    Thanks for the SQL code - I'm sure it will fix my problem - I have been left with a whole pile of trailing spaces on FirstName from someone else's conversion = makes Dear <FirstName>, look a bit silly on a merger.

    I support you re experts-exchange.com - I'm sick of their half answers coming up in searches - maybe it's downunder thunking

    Pete ( in brisbane)

  • # re: Remove trailing characters (and a small rant)
    Gravatar
    Commented on 8/15/2008 4:27 AM

    In experts-exchange, scroll down down and after the non-available answers you will see the proposed and accepted solutions without having to log into the site :p

  • # re: Remove trailing characters (and a small rant)
    Gravatar
    Commented on 4/5/2016 7:18 AM


    Nice Article !

    Really this will really help to people of SQL Server Community.
    I have also prepared small note on this, script to remove trailing character from number column in SQL Server.
    www.dbrnd.com/.../sql-server-script-to-remove-t...

Post a comment
Please add 1 and 2 and type the answer here:
Remember me?
Ensure the word in this box says 'orange':