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

  • SEARCH
  • Home
  • 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 9207731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:27:07+00:00 2026-06-18T00:27:07+00:00

Suppose I have a table, containing formatted values in a string ( nvarchar )

  • 0

Suppose I have a table, containing formatted values in a string (nvarchar) column. These values are supposed to be strings separated by some const symbol (let it be a semi-colon ;). For example,

12;0;5;dog //four values separated by a semi-colon

or

053 //if there is only one value, no semi-colon at the end

The separator is always a separator, it can’t be a part of the value.

I need to check if there is already a row in that table, with a list of values in that column, which contains at least one of the specified items. In other words I have a list of values:

List<string> list = new List<string>() { "somevalue1", "somevalue2" };

the separator:

string separator = ";";

And I need to write a linq-to-sql query doing this:

select ... from sometable
where Value='somevalue1' or Value like 'somevalue1;%' or
      Value like '%;somevalue1' or Value like '%;somevalue1;%'

   or Value='somevalue2' or Value like 'somevalue2;%' or 
      Value like '%;somevalue2' or Value like '%;somevalue2;%'

It should be mentioned that any of the searched values may contain the other. That is, I may be searching for exactly 5, while some row may contain 1;15;55. Such row must not be a match. While ...;5;... or just 5, or 5;..., or ...;5 are the matches.

Using linq-to sql I know how to do queries of the following kind:

select ... from sometable where (... or ... or ...) and (... or ...) ...

that is

IQueryable<SomeTable> query = dc.SomeTable;
foreach (string l in list)
{
    string s = l;
    query = query.Where(b => b.Value.StartsWith(s + separator) ||
                             b.Value.EndsWith(separator + s) ||
                             b.Value.Contains(separator + s + separator) ||
                             b.Value.Equals(s));
}
if (query.Any()) {/*...*/}

Obviously the Where statements are joined with AND in the resulting sql query, while I need OR everywhere.

So is there a way to get the query I need within C# code? Or the only way would be to do this with a hand-written query and DataContext.ExecuteQuery Method?

  • 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-18T00:27:09+00:00Added an answer on June 18, 2026 at 12:27 am

    I guess a UNION would suit your needs:

    IQueryable<SomeTable> baseQuery = dc.SomeTable;
    IQueryable<SomeTable> query = new List<SomeTable>().AsQueryable();
    foreach (string l in list)
    {
        string s = l;
    
        query.Union(baseQuery.Where(b => b.Value.StartsWith(s + separator) ||
                                 b.Value.EndsWith(separator + s) ||
                                 b.Value.Contains(separator + s + separator) ||
                                 b.Value.Equals(s)));
    }
    if (query.Any()) {/*...*/}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Table containing some information that I need. All these rows also
Suppose (to simplify) I have a table containing some control vs. treatment data: Which,
Suppose I have an Oracle 11.2 database containing the following table: TABLE: SURVEY PARAMETER
Suppose I have a table, the first column is an identity. I thought that
Suppose a database table containing properties of some elements: Table Element (let's say 1
Suppose I have a key,value list containing 6 keys and 6 values. I wish
I have a table in a database with one column containing dates and another
Suppose I have a table 'Tasks' with a DATETIME column approve_time . I have
Here's my problem. Suppose I have a table called persons containing, among other things,
I have a table containing some datetime columns, now I want to get the

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.