In a SQL Server 2008 database, I have a multi-column column divided by half-colonies. 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 unique values ββfrom each row in separate rows:
key:value key2:value blah foo bar A sample value:whee others
I looked at various split functions, but they all seem to be dealing with hard-coded rows, and not with rows from a column in a table. How can i do this?
Edit: Thomas received an answer! Here is my final request:
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 Yzvalue('.','nvarchar(max)') As Value From XmlCte Cross Apply XmlValue.nodes('//z') Y(z)
I assume that the material XmlValue.nodes and Yzvalue is magic. O_o
source share