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

  • Home
  • SEARCH
  • 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 581403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:34:29+00:00 2026-05-13T14:34:29+00:00

I am using SQL Server 2005. I have created a table with the columns

  • 0

I am using SQL Server 2005.

I have created a table with the columns ID and Courses. Records are as follows:

ID      Courses

1.      Java, ASP.Net, C#
2.      Java
3.      Java, C#
4.      html

The Courses column is of type varchar and the values in it are comma separated.
I want to separate every word and store it in another or temp. table.

Output must be like this:

ID      Courses

1.      Java
2.      ASP.Net
3.      C#
4.      html

Here ID is not important.

Thank you.

  • 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-13T14:34:29+00:00Added an answer on May 13, 2026 at 2:34 pm

    see my previous answer to this

    this is the best source:

    http://www.sommarskog.se/arrays-in-sql.html

    create a split function, and use it like:

    SELECT
        *
        FROM YourTable  y
        INNER JOIN dbo.splitFunction(@Parameter) s ON y.ID=s.Value
    

    I prefer the number table approach

    For this method to work, you need to do this one time table setup:

    SELECT TOP 10000 IDENTITY(int,1,1) AS Number
        INTO Numbers
        FROM sys.objects s1
        CROSS JOIN sys.objects s2
    ALTER TABLE Numbers ADD CONSTRAINT PK_Numbers PRIMARY KEY CLUSTERED (Number)
    

    Once the Numbers table is set up, create this function:

    CREATE FUNCTION [dbo].[FN_ListToTable]
    (
         @SplitOn  char(1)      --REQUIRED, the character to split the @List string on
        ,@List     varchar(8000)--REQUIRED, the list to split apart
    )
    RETURNS TABLE
    AS
    RETURN 
    (
    
        ----------------
        --SINGLE QUERY-- --this will not return empty rows
        ----------------
        SELECT
            ListValue
            FROM (SELECT
                      LTRIM(RTRIM(SUBSTRING(List2, number+1, CHARINDEX(@SplitOn, List2, number+1)-number - 1))) AS ListValue
                      FROM (
                               SELECT @SplitOn + @List + @SplitOn AS List2
                           ) AS dt
                          INNER JOIN Numbers n ON n.Number < LEN(dt.List2)
                      WHERE SUBSTRING(List2, number, 1) = @SplitOn
                 ) dt2
            WHERE ListValue IS NOT NULL AND ListValue!=''
    
    );
    GO 
    

    You can now easily split a CSV string into a table and join on it:

    select * from dbo.FN_ListToTable(',','1,2,3,,,4,5,6777,,,')
    

    OUTPUT:

    ListValue
    -----------------------
    1
    2
    3
    4
    5
    6777
    
    (6 row(s) affected)
    

    To make what you need work, use CROSS APPLY:

    DECLARE @tbl_A table (RowID int, RowValue varchar(500))
    DECLARE @tbl_b table (RowID int identity, RowValue varchar(500))
    
    INSERT INTO @tbl_A VALUES (1, 'Java, ASP.Net, C#')
    INSERT INTO @tbl_A VALUES (2, 'Java')
    INSERT INTO @tbl_A VALUES (3, 'Java, C#')
    INSERT INTO @tbl_A VALUES (4, 'html')
    
    INSERT INTO @tbl_b (RowValue)
    SELECT DISTINCT
        st.ListValue
        FROM @tbl_A 
            CROSS APPLY  dbo.FN_ListToTable(',',RowValue) AS st
        ORDER BY st.ListValue
    
    SELECT * FROM @tbl_b ORDER BY RowID
    

    OUTPUT:

    RowID       RowValue
    ----------- --------------
    1           ASP.Net
    2           C#
    3           html
    4           Java
    
    (4 row(s) affected)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 348k
  • Answers 348k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can get and set the element's current scroll position… May 14, 2026 at 6:39 am
  • Editorial Team
    Editorial Team added an answer If table contains several records, i.e.: 1, name1, .. 2,… May 14, 2026 at 6:39 am
  • Editorial Team
    Editorial Team added an answer From what you explained - it seems that the main… May 14, 2026 at 6:39 am

Related Questions

I have created a user using the built-in CreateUserWizard - control. I can now
I have created a reddot cms component, in which I added this line Also,
I'm using SQL Server 2005 with Reporting Services. I have many reports installed, some
I have created a user defined function to gain performance with queries containing 'WHERE
I am using T-SQL query directly in Microsoft SQL Server Studio's Query window against

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.