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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:23:50+00:00 2026-05-30T19:23:50+00:00

I have a SQL Server database table with a column called resources. Each cell

  • 0

I have a SQL Server database table with a column called resources. Each cell of this column contains a comma-delimited list of integers. So the table data might look like this:

Product_ID    Resources    Condition
1             12,4,253     New
2             4,98,102,99  New
3             245,88       Used
etc....

I want to return the rows where a resource ID number is contained in the resources column. This doesn’t work, but something like this:

SELECT *
FROM   product_table
WHERE  resources CONTAINS 4

If this was working, it would return the rows for product_id 1 and 2 because both of the resources cells in those rows contain the value 4. It would not return product_id 3, even though the resources cell for that row has the number 4 in it, because it’s not the full comma-delimited value.

What is the correct way to do this?

  • 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-30T19:23:52+00:00Added an answer on May 30, 2026 at 7:23 pm

    Use the Split function as outlined in this resource:

    CREATE FUNCTION Split
    (
      @delimited nvarchar(max),
      @delimiter nvarchar(100)
    ) RETURNS @t TABLE
    (
    -- Id column can be commented out, not required for sql splitting string
      id int identity(1,1), -- I use this column for numbering splitted parts
      val nvarchar(max)
    )
    AS
    BEGIN
      declare @xml xml
      set @xml = N'<root><r>' + replace(@delimited,@delimiter,'</r><r>') + '</r></root>'
    
      insert into @t(val)
      select 
        r.value('.','varchar(5)') as item
      from @xml.nodes('//root/r') as records(r)
    
      RETURN
    END
    GO
    
    -- Create the test table and insert the test data
    create table #test
    (
    product_id int, 
    resources nvarchar(max), 
    condition nvarchar(10)
    );
    
    insert into #test (product_id, resources, condition)
    select 1, '12,4,253', 'new'
    union
    select 2, '4,98,102,99', 'new'
    union 
    select 3, '245,88', 'used';
    
    -- Use the Split function and cross apply to grab the data you need
    
    select product_id, val, condition
    from #test
    cross apply dbo.split(#test.resources,',') split
    where val = '4' -- split returns a string so use single quotes
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL Server 2008 database. This database has a Table called Book.
I have a table like this in my database (SQL Server 2008) ID Type
database/SQL novice here. I have a table with a column called, for example, EmployeeID.
Current Implementation Sql Server 2005 Database with a table called messages with a column
Lets say I have a table in a sql server 2000 database called TransactionType:
I have table in my SQL Server database called OrderDetail which stores the order
i have a char(10) column in a table in a SQL-Server 2005 database: CREATE
I have a table in my SQL Server database called items which has a
We have a database called AVL in SQL Server 2008 R2 SE. This database
I have a table in a SQL Server 2008 database. This table has a

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.