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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:16:40+00:00 2026-05-20T15:16:40+00:00

mytable structure : id int, lookuptablename varchar 1, ‘lookuptable1’ 2, ‘lookuptable2’ lookuptable1 : id

  • 0

mytable structure: id int, lookuptablename varchar

1, 'lookuptable1'
2, 'lookuptable2'

lookuptable1: id int, item varchar

1, 'item1 from lkt1'
2, 'item2 from lkt1'

lookuptable2: id int, item varchar

1, 'item1 from lkt2'
2, 'item2 from lkt2'

Query:

SELECT GetDelimitedList(lookuptablename) FROM mytable;

Expected result:

1,2~item1 from lkt1,item2 from lkt1
1,2~item1 from lkt2,item2 from lkt2

I have been struggling to find out a way to accomplish this in various ways but just couldn’t figure it out.

  • 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-20T15:16:40+00:00Added an answer on May 20, 2026 at 3:16 pm

    A workaround. UDFs won’t work. Maybe CLR, but not native SQL UDF.

    First create this proc, which mashes a table into a single row

    create proc dbo.GetDelimitedList
    @tablename sysname
    AS
    declare @sql nvarchar(max)
    set @sql = '
    declare @id nvarchar(max), @item nvarchar(max)
    select
        @id = isnull(@id+'','','''') + convert(varchar,id),
        @item = isnull(@item+'','','''') + item
    from ' + quotename(@tablename) + '
    select @id + ''~'' + @item'
    exec (@sql)
    GO
    

    Then use this SQL batch to produce the output equivalent to SELECT GetDelimitedList(tablename) FROM mytable;

    declare @tmp table(id int, mashed nvarchar(max))
    declare @id int, @tablename sysname
    -- start at first table
    select top 1 @id = id, @tablename = tablename
    from mytable
    order by id asc
    while @@ROWCOUNT > 0
    begin
        -- fill our temp table
        insert @tmp (mashed) exec GetDelimitedList 'mytablelist'
        update @tmp set id = @id where id is null
        -- next table
        select top 1 @id=id, @tablename = tablename
        from mytable
        where id > @id
        order by id asc
    end
    SELECT * FROM @tmp;
    

    Sample tables used:

    create table mytable(id int, tablename varchar(100))
    insert mytable values (1, 'mytablelist')
    insert mytable values (3, 'mytablelist2')
    
    create table mytablelist(id int, item varchar(100))
    insert mytablelist values
    (1, 'item1'),
    (2, 'item2')
    GO
    
    create table mytablelist2(id int, item varchar(100))
    insert mytablelist2 values
    (11, 't2item1'),
    (22, 't2item2')
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My table structure is below : MyTable (ID Int, AccID1 Int, AccID2 Int, AccID3
My table structure is: TABLE `licenses` ( `id` int(11) NOT NULL auto_increment, `code` varchar(30)
Here is my table structure MyTable ----------- ObjectID int (Identity), -- Primary Key FileName
This is my table structure fName Friend's Name [Varchar] fUID Friend's ID [Int] UID
I have the following table structure: EVENT_ID(INT) EVENT_NAME(VARCHAR) EVENT_DATE(DATETIME) EVENT_OWNER(INT) I need to add
my table structure is CREATE TABLE [dbo].[Emp]( [ID] [int] NOT NULL, [EmpName] [varchar](50) NOT
I have a table with the following structure: CREATE TABLE MyTable ( ID int
My table structure is below: CREATE TABLE [ACC].[Document]( [DocumentID] [int] IDENTITY(1,1) NOT NULL, [Date]
Structure of my table : ID(int) | NUMBER(int) | CREATED_AT(date) If I have three
I have a database table structure as follow: datatype data mytable now datatype has

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.