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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:41:46+00:00 2026-06-17T12:41:46+00:00

I have 2 simplified tables (all columns are varchar ). Some rows in T1_TAB

  • 0

I have 2 simplified tables (all columns are varchar). Some rows in T1_TAB for F2 contain multiple values separated by ;, some do not have separators at all as shown below (sometimes ; might also appear at the beginning and/or at the end). F2 in T2_TAB always has a single value.

I need to be able to pull rows from ether table based on single selection from one table and likeliness on F2 columns.

T1_TAB

F0   |  F2
--------------
1          ;30
2       ;10;20;30
3          ;20;30;
4          10

T2_TAB

F1   |  F2
-------------
100       10    
200       20      
300       30

I can do:

SELECT T1.F0
FROM T1_TAB T1 
LEFT JOIN T2_TAB T2
ON T2.F2 LIKE '%' + T1.F2 + '%'
WHERE T2.F1 = '200'

This would bare result:

2
3

Now, I need to do the opposite. For instance:

Based on condition WHERE T1.F0 = 3, I need to pull from T2 rows with F1 equals 200 and 300 respectively. I guess I need to somehow split ;20;30; by a “;” and do the loop to match each value separately at run-time disregarding blank tokens.

  • 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-17T12:41:46+00:00Added an answer on June 17, 2026 at 12:41 pm

    You can create a function which converts the semicolon-separated string into a table of values:

    create function CreateTableFromList(@Values varchar(1000))
    returns @table table (id int)
    as
    begin
    declare @p int = 1, @q int = 1, @n int = len(@Values)
    
    while @p<@n begin
      set @q = CHARINDEX(';',@Values,@p)
      if @q=0 set @q=@n + 1
      if @q > @p 
        insert into @table values (cast(substring(@Values,@p,@q-@p) as int))
      set @p= @q + 1
    end
    return
    end
    

    and then

    select T2.F1 
      from T2
    where T2.F2 in (
      select ID 
        from T1 
             cross apply dbo.CreateTableFromList(T1.F2) 
      where T1.F0=3
      )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a (simplified) table consisting of three columns: id INT PRIMARY KEY NOT
I have some tables that contain data about players and the games they have
I have the following (simplified) database tables: Products - ProductID, int, PK - Name,
I've got the following problem: I have two tables: (simplified) +--------+ +-----------+ | User
I have two tables with the following (simplified) structures: table "Factors" which holds data
I have a table with the following columns (I simplified it a little): PRODUCT_name
I have (simplified for this question) a table 'TAB' with two columns 'id' (integer
I have a MySQL database with two tables (simplified for this question): movies table
Basically the situation is like this (simplified, pseudo code): I have 2 TABLES person
I have a schema with many related tables. A view let me agglomerate all

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.