Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7985115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:28:33+00:00 2026-06-04T11:28:33+00:00

I have a large table in SQL; one field contains the user’s name, which

  • 0

I have a large table in SQL; one field contains the user’s name, which is often followed by various things I need to strip off to obtain their ‘plain’ name (don’t ask!) Eg:

<pre>Mark Johnson
Joe Bloggs (DO NOT USE)
Mick Bronson (refer Jim Bloggs)
Jan Morrison
Jemima Thomson refer Joe harrison
Glen Grabs-Moffat try harry

There are ~20 types of postfix. I’d like to create an UPDATE query (probably 20 I’m guessing) that will ‘trim’ the value from the start of my provided strings eg ” (DO” or ” (ref” to get “Joe Bloggs” only with no postfix. Preferably it’d be case insensitive.

Any ideas?

Thanks

EDIT:

The code I was using looked like this:

for (int count = 0; count < ExpenseItems.Count; count++)
            {
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf("(DO NOT").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf("(DON'T").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf("(DONT ").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf("(DONOT").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf(" DO NOT").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf(" DON'T").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf(" DONT ").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf(" DONOT").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf("(pls").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf("(please").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf(" pls").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf(" please").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf("(refer").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf(" refer").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf(" (Re").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf(" (ref to").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf(" ref to").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf(" (refto").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf(" refto").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf(" use ").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf(" try ").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf("(see ").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf(" see ").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf("director").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf(" never ").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.TruncateFromStartOf(" moved").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.Replace("DISABLED", "(D)").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.Replace("disabled", "(D)").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.Replace("Disabled", "(D)").Trim();
                ExpenseItems[count].Requester_Name = ExpenseItems[count].Requester_Name.Replace("DISALBED", "(D)").Trim();
            }

The truncate does what it says on the tin:

    public static string TruncateFromStartOf(this string input, string splitString, bool caseSensitive = false, int offset = 0)
    {
        //Verify input
        if (string.IsNullOrEmpty(input))
            return string.Empty;

        if (string.IsNullOrEmpty(splitString))
            return input;

        int segmentIndex = -1;
        //the start of the segment in the input string
        if (caseSensitive)
        {
            segmentIndex = input.IndexOf(splitString, StringComparison.Ordinal);
        }
        else
        {
            segmentIndex = input.ToLower().IndexOf(splitString.ToLower(), StringComparison.Ordinal);
        }

        if (segmentIndex == -1)
            return input; //nothing to remove

        //Return the parts around the segment
        return input.Substring(0, segmentIndex + offset);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:28:34+00:00Added an answer on June 4, 2026 at 11:28 am

    Put your exclusion words in a table instead of storing them in code:

    CREATE TABLE dbo.TruncationWords
    (
           Word VARCHAR(32) NOT NULL UNIQUE
    );
    
    INSERT dbo.TruncationWords(Word) 
    SELECT '(DO NOT'
    UNION ALL SELECT '(DON''T'
    UNION ALL SELECT '(DONT'
    UNION ALL SELECT '(DONOT'
    UNION ALL SELECT 'DO NOT'
    UNION ALL SELECT 'DON''T'
    UNION ALL SELECT 'DONT'
    UNION ALL SELECT 'DONOT'
    UNION ALL SELECT '(pls'
    UNION ALL SELECT '(please'
    UNION ALL SELECT 'pls'
    UNION ALL SELECT 'please'
    UNION ALL SELECT '(refer'
    UNION ALL SELECT 'refer'
    UNION ALL SELECT '(Re'
    UNION ALL SELECT '(ref to'
    UNION ALL SELECT 'ref to'
    UNION ALL SELECT '(refto'
    UNION ALL SELECT 'refto'
    UNION ALL SELECT 'use'
    UNION ALL SELECT 'try'
    UNION ALL SELECT '(see'
    UNION ALL SELECT 'see'
    UNION ALL SELECT 'director'
    UNION ALL SELECT 'never'
    UNION ALL SELECT 'moved'
    UNION ALL SELECT 'disabled';
    

    Now you can easily cross-ref these words against any table/column. For example:

    DECLARE @t TABLE (Name VARCHAR(255));
    
    INSERT @t SELECT 'Mark Johnson'
    UNION ALL SELECT 'Joe Bloggs (DO NOT USE)'
    UNION ALL SELECT 'Mick Bronson (refer Jim Bloggs)'
    UNION ALL SELECT 'Jan Morrison'
    UNION ALL SELECT 'Jemima Thomson refer Joe harrison'
    UNION ALL SELECT 'Glen Grabs-Moffat try harry'
    UNION ALL SELECT 'Can''t touch this';
    
    ;WITH x AS
    (
      SELECT 
        t.Name, 
        Trunc = LEFT(t.Name, CHARINDEX(' ' + w.Word, t.Name)),
        rn = ROW_NUMBER() OVER (PARTITION BY t.Name ORDER BY CHARINDEX(' ' + w.Word, t.Name))
       FROM @t AS t
       INNER JOIN dbo.TruncationWords AS w
       ON CHARINDEX(' ' + w.Word, t.Name) > 0
    )
    UPDATE src
      SET src.Name = x.Trunc
      FROM @t AS src
      INNER JOIN x 
      ON src.Name = x.Name
      WHERE x.rn = 1;
    
    SELECT Name FROM @t;
    

    Results:

    Name
    --------------------------
    Mark Johnson
    Joe Bloggs
    Mick Bronson
    Jan Morrison
    Jemima Thomson
    Glen Grabs-Moffat
    Can't touch this
    

    This solution makes two assumptions:

    1. That the word you want to truncate is always separated by a space.
    2. That the collation is case insensitive. You can use the COLLATE clause to work around this.

    Also I think words like 'see' are problematic. What if someone has the name 'John Seek'?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very large (millions of rows) SQL table which represents name-value pairs
I'm useing SQL Ser 2008 and have a large table with only one column
I have a large table (between 74 and 88million rows) which is the middle
1) My question is that, when i have two large table which cannot be
I also have a very large table in SQL Server (2008 R2 Developer Edition)
I have a SQL Mobile database with one table. It has several columns with
I have a table with a few relational columns and one XML column which
I have a dataset which contains a string key field and up to 50
We have a large table in SQL Server with almost 40.000.000 records. it took
I have a large CSV file containing a list of stores, in which one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.