Trim a word from all rows returned

  • Hi all,

    I have a returned result as follows:

    Computer and Mathematical Occupations

    Healthcare Practitioners and Technical Occupations

    Management Occupations

    Office and Administrative Support Occupations

    what I want to do is to make the sql query return these data without the word "Occupations" which is at the end of statement.

    Is there a sql function can do so?

    Thanks in advance.

  • Hi,
    Yes you can used the replace function for this purpose.
    SELECT REPLACE(FieldName,'Occupations','')
    Hope this will slove your problem
    Cheers

    cheers

  • Thanks alot.

    It ran correcly

  • Ya but it works only if the word occupation is only found once in the sentence. 

     

    You might want to add this where condition :

    SELECT CASE WHEN FieldName LIKE '% occupation' THEN LEFT(FieldName, LEN(FieldName) - 11 /* length of occupation.. adjust depending on spaces*/

    ELSE FieldName

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

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