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 9215221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:09:23+00:00 2026-06-18T02:09:23+00:00

Is it possible to do a LINQ where clause and split a varchar field

  • 0

Is it possible to do a LINQ where clause and split a varchar field on a : into a collection and compare this to another collection to see if any values match.

For example, we have a List<string> called AllowedHolders which contains ARR ACC etc.. however the field in the database (which unfortunately we cannot change) is a varchar but has values separated by a colon: i.e. “:ARR:ACC:”

What we would like to do is write a LINQ where clause which can check if any of the AllowedHolders appear in the field. As we wish to restrict the results to only bring back records where the field contains a value in the AllowedHolders collection.

We have done the following where the field only contains a single value

searchResults = searchResults.Where(S => searchParams.AllowedBusinessAreas.Contains(S.SIT_BusinessArea));

But the following will not work because SIT_HolderNames contains values separated by a colon:

searchResults = searchResults.Where(S => searchParams.AllowedHolders.Contains(S.SIT_HolderName)

Any ideas would be much appreciated. If you need me to explain anything further please let me know.

Andy

  • 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-18T02:09:24+00:00Added an answer on June 18, 2026 at 2:09 am

    Maybe you can use:

    searchResults = searchResults.Where(S => searchParams.AllowedHolders
      .Any(H => S.SIT_HolderName.Contains(H))
      );
    

    or

    searchResults = searchResults.Where(S => searchParams.AllowedHolders
      .Any(S.SIT_HolderName.Contains)
      );
    

    As pointed out by the first comment, this only works if no holder name contains another holder name as a substring. I was implicitly assuming that all your holder names were three-letter strings like ARR and ACC. If this is not the case, consider using (":" + H + ":"), or find a more safe solution.

    Edit: Just for completeness, here are two versions with colons prepended and appended:

    // OK if some name is contained in another name as a substring
    // Requires colon before the first and after the last name
    searchResults = searchResults.Where(S => searchParams.AllowedHolders
      .Any(H => S.SIT_HolderName.Contains(":" + H + ":"))
      );
    

    And:

    // OK if some name is contained in another name as a substring
    // Ugly checks included to handle cases where no colons are present in the extreme ends
    searchResults = searchResults.Where(S => searchParams.AllowedHolders
      .Any(H => S.SIT_HolderName.Contains(":" + H + ":") || S.SIT_HolderName.StartsWith(H + ":") || S.SIT_HolderName.EndsWith(":" + H) || S.SIT_HolderName == H)
      );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible in LINQ to do this: Group by a field (LineTotal), returning
Possible Duplicate: Linq performance for in-memory collection I have a web application with around
I don't know if this is possible in Linq but here goes... I have
Possible Duplicate: “NOT IN” clause in LINQ to Entities I work with the schema
I'm not sure if this is possible in LINQ, but I have the following
I know this is possible in LINQ-to-SQL, and I've seen bits and pieces that
Is it possible to write a linq select with a where clause which can
Possible Duplicates: Linq to Entities - Sql “IN” clause How to implement SQL “in”
I was wondering whether it's possible to add/remove a where clause from a linq
Is is possible to put a constant where clause to a Linq to SQl

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.