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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:06:45+00:00 2026-05-23T07:06:45+00:00

In a SQL Server 2008 database, I have a column with multiple values separated

  • 0

In a SQL Server 2008 database, I have a column with multiple values separated by semi-colons. Some values contain colons. Sample data:

key:value;key2:value;blah;foo;bar;A sample value:whee;others
key:value;blah;bar;others
A sample value:whee

I want to get all the unique values from each row in separate rows:

key:value
key2:value
blah
foo
bar
A sample value:whee
others

I’ve looked at various split functions, but they all seem to deal with hard-coded strings, not strings coming from a column in a table. How can I do this?

Edit: Thomas’ answer got it! Here was my final query:

With SampleInputs As
    (
    select distinct myColumn from [myDatabase].[dbo].myTable where myColumn != ''
    )
    , XmlCte As
    (
    Select Cast( '<z>' + Replace( myColumn, ';', '</z><z>' ) + '</z>' As xml ) As XmlValue
    From SampleInputs As I
    )
Select Distinct Y.z.value('.','nvarchar(max)') As Value
From XmlCte
    Cross Apply XmlValue.nodes('//z') Y(z)

I’m guessing the XmlValue.nodes and Y.z.value stuff is magic. O_o

  • 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-23T07:06:46+00:00Added an answer on May 23, 2026 at 7:06 am
    With SampleInputs As
        (
        Select 'key:value;key2:value;blah;foo;bar;A sample value:whee;others' As [Data]
        Union All Select 'key:value;blah;bar;others' 
        Union All Select 'A sample value:whee'
        )
        , XmlCte As
        (
        Select Cast( '<z>' + Replace( I.[Data], ';', '</z><z>' ) + '</z>' As xml ) As XmlValue
        From SampleInputs As I
        )
    Select Distinct Y.z.value('.','nvarchar(max)') As Value
    From XmlCte
        Cross Apply XmlValue.nodes('//z') Y(z)
    

    Update

    Here’s a version of the above that handles entities:

    With SampleInputs As
        (
        Select 'key:value;key2:value;blah;foo;bar;A sample value:whee;others' As [Data]
        Union All Select 'key:value;blah;bar;others' 
        Union All Select 'A sample value:whee'
        Union All Select 'A sample value:<Oops>'
        )
        , XmlGoo As
        (
        Select Cast(
                Replace(
                    Replace( Cast( Z.XmlValue As nvarchar(max) ), '{{', '<z>' )
                    , '}}', '</z>')
                As Xml ) As Xmlvalue
        From    (
                Select Cast(
                        (
                        Select '{{' + Replace( [Data], ';', '}}{{' ) + '}}'
                        From SampleInputs
                        For Xml Path(''), type
                        ) As Xml ) As XmlValue
                ) As Z
        )
    Select Distinct Z.data.value('.', 'nvarchar(max)')
    From XmlGoo
        Cross Apply XmlValue.nodes('/z') Z(data)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some extended property column descriptions in a SQL Server 2008 database, and
I have a database table in Sql Server 2008 R2 which contains data stored
I have a table ContentHistory in a SQL Server 2008 database with a column
I have a table with a time column in my SQL Server 2008 database.
I have a database column in a SQL Server 2008 database that contains VARCHAR
Our database server is a SQL 2008 server. My colleagues all have XP service
I'm looking at the AdventureWorks sample database for SQL Server 2008, and I see
I'm helping implement a SQL Server 2008 database and I have several columns that
I need to localize data in tables in a SQL Server 2008 database. Each
I have a SQL Server 2008 database with 2 tables. These tables are defined

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.