searching for ending and deleting

  • Dear All , 

    I am having question ,i have column that some time ends with mr / mrs or chd01 and some time without ending ,  i am looking for script that helps me to get rid of this endings if its there how can i do that ?

    thank you for your kind assistant.
    Regards

    Rashed

  • You would need to update those, removing the proper number of characters (Use LEFT() and LEN() in an update query... Since you only have a few cases, you could write a different UPDATE statement for each case.

    CREATE TABLE #Dummy( RandomString VARCHAR(100));
    GO
    INSERT INTO #Dummy(RandomString)
    VALUES ('I got some stuff for Mr.'),
            ('Come ask the Mrs.'),
            ('Nobody here, boys.'),
            ('Hey, Mr., Gimme some money!');

    SELECT *
    FROM #Dummy
    WHERE RandomString LIKE '%Mr.'
    OR RandomString LIKE '%Mrs.';

  • HI , thanks for your quick response , incase i am having the value 'Mr' as part of the value how its going to handle it like in the sample below ? 
    CREATE TABLE #Dummy( RandomString VARCHAR(100));
    GO
    INSERT INTO #Dummy(RandomString)
    VALUES ('I got some mr stuff for Mr.'),
       ('Come mrs ask the Mrs.'),
       ('Nobody here, boys.'),
       ('Hey, Mr., Gimme some money!');

    SELECT *
    FROM #Dummy
    WHERE RandomString LIKE '%Mr.'
    OR RandomString LIKE '%Mrs.';


    regards

    Rashed

  • You really need to open up SSMS and try learning something.

    How about the painfully obvious:

    SELECT *
    FROM #Dummy
    WHERE RandomString LIKE '%Mr. %'
    OR RandomString LIKE '%Mrs. %';

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

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