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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:39:49+00:00 2026-05-24T08:39:49+00:00

I am working on a query page where a user selects a value which

  • 0

I am working on a query page where a user selects a value which represents different types, each identified by an ID.
The problem is selecting these IDs from the data base using the WHERE IN method.

This is my SQL statement

SELECT M.REG_NO, T.TYPE_ID 
    FROM MAIN AS M 
        INNER JOIN CLASSIFICATION AS C 
            ON M.REG_NO = C.REG_NO
        INNER JOIN TYPE AS T 
            ON T.TYPE_ID = C.TYPE_ID
    WHERE T.TYPE_ID IN (@Types)

it will work for one single value, eg. 46, but NOT if the value is in brackets, eg. (46) or (’46’), the way it should be for the IN.

I am using visual studio which is auto generating the method to access the table adapter to get the values so I think I HAVE to do this through SQL.

I am passing a string, eg. Types = “46,267,2010” , into the adapter method which passes the string into the @Types in the SQL statement.

Any help would be great. Thanks!

  • 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-05-24T08:39:51+00:00Added an answer on May 24, 2026 at 8:39 am

    This is a pretty common problem — not sure why TSQL hasn’t dealt with it yet. Anyway, the solution I’ve found works best for me is to convert the variable to a table, and then you can use IN() on it just fine.

    Starting with the function:

    CREATE Function [dbo].[ParseStringList]  (@StringArray nvarchar(max) )  
    Returns @tbl_string Table  (ParsedString nvarchar(max))  As  
    
    BEGIN 
    
    DECLARE @end Int,
            @start Int
    
    SET @stringArray =  @StringArray + ',' 
    SET @start=1
    SET @end=1
    
    WHILE @end<Len(@StringArray)
        BEGIN
            SET @end = CharIndex(',', @StringArray, @end)
            INSERT INTO @tbl_string 
                SELECT
                    Substring(@StringArray, @start, @end-@start)
    
            SET @start=@end+1
            SET @end = @end+1
        END
    
    RETURN
    END
    

    And then to use the function…

    SELECT * 
    FROM table
    WHERE SomeFieldValue In (Select ParsedString From dbo.ParseStringList(@Types))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on .aspx page that uses a t-sql query that uses a
i have been working on query which uses compute by clause for avg and
Below is a mysql query I am working on for a page that hase
I'm working on a PHP page that allows the user to reset their password.
I'm working on a profile page, where a registered user can update their information.
I have below a working query that needs to be simplified. The reason is
I have this query working but it is not returning back exactly what I
I'm trying to get a query working that takes the values (sometimes just the
I am stuck figuring out a working SQL Query for the fallowing: I need
I'm working on a query with a varchar column called ALCOHOL_OZ_PER_WK . Part of

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.