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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:49:14+00:00 2026-06-02T23:49:14+00:00

I have web application developed in C#, where a page is showing the output

  • 0

I have web application developed in C#, where a page is showing the output of a SQL query; the query is a linq call to a store procedure and I am using SQL Server 2008.

One of the column display the tags associated with the result line; on the same page a list of check-boxes is displayed, each check-box correspond to a tag, and if the user turn on or off one or multiple check-box I want to filter the query.

My simplest SQL solution would be to us “NOT IN” like the following:

select * from [mytable] where [tags] not in ('tag1','tag2, etc...)

Given I convert the FORM POST to a string with comma separated values.
Example:

string tags = ParseFormAndConvertCheckBoxToCSV(Page.Request.Form);
string sqlcmd = "select * from [mytable] where [tags] not in (" + tags + ")";

But I don’t want to dynamically build the SQL because as far as I know that would be bad.

I can imagine few way of splitting the string with comma separated list of values in SQL nd store the values into a in-memory table:

declare @tagscsv nvarchar(MAX)
declare @notags TABLE(Value nvarchar(50))

set @tagscsv = 'taxi,ivf'

Declare @x XML 
select @x = cast('<A>'+ replace(@tagscsv,',','</A><A>')+ '</A>' as xml)

insert into @notags
select t.value('.', 'nvarchar(50)') as v from @x.nodes('/A') as x(t)

select * from [mytable] where [tags] not in (select * from @notags)

…but this too sounds like a dirty trick.

To me it looks like this should be a very common situation, and I figure out a lot of people out there faced this problem in the past, but searching on google I could not find an elegant solution.

Anyone can help?

  • 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-02T23:49:16+00:00Added an answer on June 2, 2026 at 11:49 pm

    Edit: Missed the stored procedure part.
    With stored procedures you do not have a lot of options. I usually do what you did, split the comma seperated string and save the values to a temp table (or table variable).

    CREATE PROCEDURE SplitAndStuff
        @List nvarchar(MAX) = NULL,
        @SplitOn nvarchar(5) = ','  --This can be replaced with a literal if it is always a comma.
    AS
    BEGIN
        DECLARE @Pos int;
        DECLARE @SplitOnLength int;
        DECLARE @Results TABLE (value nvarchar(MAX))
        SET @SplitOnLength = DATALENGTH(@SplitOn) / 2;
    
        IF (RIGHT(@List, @SplitOnLength) <> @SplitOn) SET @List = @List + @SplitOn; --Add trailling split string if there is not one already.
    
        SET @Pos = CHARINDEX(@SplitOn, @List, 1)                                    --Initalize for loop.  (The starting position returned is 1-based, not 0-based.)
    
        WHILE @Pos > 0
        BEGIN
            INSERT INTO @Results (value) SELECT CAST(SUBSTRING(@List,1,@Pos-1)AS int);
    
            SET @List = SUBSTRING(@List, @Pos+@SplitOnLength, DATALENGTH(@List) / 2);
            SET @Pos = CHARINDEX(@SplitOn, @List, 1);
        END
    END
    GO
    

    If your stored procedure is not doing anything else (besides the look up) you could use my original LINQ answer below:

    Since you are using LINQ you need to split tagscsv and use the resulting array to perform an “where in” query:

    string[] tags = tagscsv.Split(',');
    var output = from q in db.Table where !tags.Contains(q) select q;
    

    See also:

    • http://msdn.microsoft.com/en-us/library/ms132407.aspx
    • Using LINQ to Perform “WHERE IN (Value1,Value2)” Queries
    • The NOT IN clause in LINQ to SQL
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed an web application using JSP and deployed in tomcat server. In
I have a ASP.net 3.5 web application developed in VB.net I am using iTextsharp
I have developed a web application and various clients can store records to that
I have developed a web application using Netbeans 6.7 and Ant. The webapp works,
We have a web application that runs on IIS using .NET 2.0 developed and
I have developed an web application using xhtml, jQuery, Ajax, java, Servlets & tomcat
I have a web application developed in ASP.NET 2.0, deployed in a data center.
I have a web application developed with Spring 2.5. The application has numerous controllers,
I have a web application developed with Struts2, JSP, JPA, Spring and MySql. I
My boss have given me assignment to find how a web based application developed

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.