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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:38:14+00:00 2026-06-08T21:38:14+00:00

In my table, I have a varchar column whereby multi-values are stored. An example

  • 0

In my table, I have a varchar column whereby multi-values are stored. An example of my table:

RecNum           |  Title   |  Category
-----------------------------------------
wja-2012-000001  |  abcdef  |  4,6
wja-2012-000002  |  qwerty  |  1,3,7
wja-2012-000003  |  asdffg  |   
wja-2012-000004  |  zxcvbb  |  2,7
wja-2012-000005  |  ploiuh  |  3,4,12

The values in the Category column points to another table.

How can I return the relevant rows if I want to retrieve the rows with value 1,3,5,6,8 in the Category column?

When I tried using IN, I get the ‘Conversion failed when converting the varchar value ‘1,3,5,6,8’ to data type int’ error.

  • 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-08T21:38:17+00:00Added an answer on June 8, 2026 at 9:38 pm

    Breaking the Categories out into a separate table would be a better design if that’s a change you can make… otherwise, you could create a function to split the values into a table of integers like this:

    CREATE FUNCTION dbo.Split(@String varchar(8000), @Delimiter char(1))
    returns @temptable TABLE (id int)
    as
    begin
        declare @idx int
        declare @slice varchar(8000)
    
        select @idx = 1
            if len(@String)<1 or @String is null  return
    
        while @idx!= 0
        begin
            set @idx = charindex(@Delimiter,@String)
            if @idx!=0
                set @slice = left(@String,@idx - 1)
            else
                set @slice = @String
    
            if(len(@slice)>0)
                insert into @temptable(id) values(convert(int, @slice))
    
            set @String = right(@String,len(@String) - @idx)
            if len(@String) = 0 break
        end
    return
    end
    

    Then call it from your query:

    SELECT ...
    FROM ...
    WHERE @SomeID IN (SELECT id FROM dbo.Split(Category, ','))
    

    Or if you’re looking to provide a list of categories as an input parameter (such as ‘1,3,5,6,8’), and return all records in your table that contain at least one of these values, you could use a query like this:

    SELECT ...
    FROM ...
    WHERE
        EXISTS (
            select 1
            from dbo.Split(Category, ',') s1
            join dbo.Split(@SearchValues, ',') s2 ON s1.id = s2.id
        )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have varchar column Name in table. Rows contain values, for example 'Test', 'tEst',
In a MySQL-table I have a VARCHAR -column with different values, which may represent
i have table and column varchar type column id and values are m1, m2,
I have a table with a varchar column, and I want to find values
I have a table with a varchar column with values that should be integers
I have a varchar(100) column in a table that contains a mix of integers
I have table with column Percentage varchar(10) Data in that table is Pecentage 2/10
So if I have a table as follows with column date datetime employee varchar
I have created a new table including a column note. The default is varchar(255)
I have a table in MS SQL Server 2008 with a varchar column called

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.