how do I remove the last 4 characters

  • Hi I need to replace a memo field called "desc" with itself minus the last four characters.

    Somebody has run a process which puts a rude word on the end of the decsriptions

    thanks ps its sql server 2000

  • two ways...you can use the REPLACE function to replace the bad word with an empty string:

    UPDATE MYTABLE SET MYCOLUMN = REPLACE(MYCOLUMN,'BADWORD','')

    this is a better solution, because if the bad word does not exist, nothing gets replaced.

    If you just whack every column to remove the last 4 characters, you might chop something you didn't really want to do; you'd want to at least use a WHERE statement to test for the bad word:

    UPDATE MYTABLE SET MYCOLUMN = LEFT(MYCOLUMN,LEN(MYCOLUMN - 4) WHERE MYCOLUMN LIKE '%BADWORD'

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply