Home > Net >  SQL server: Looking for solution to convert columns values/data to rows
SQL server: Looking for solution to convert columns values/data to rows

Time:10-09

I have a scenario where I need to convert column values to rows. As you see below I have a table name Test and a column named 'value' and I want the data in that column into rows. I am using SQL Server. Can you help me with the T-SQL script to achieve the below? Apologies if anything is missing

Original

Value 0130509667,0130509791,0130509824,0130509811,0130503549,0130503547,0130509323,0130509320,0130509145,0130509315

Please see the raw data

Output

Value

0130509667 0130509791 0130509824 0130509811 0130503549 0130503547 0130509323 0130509320 0130509145 0130509315

Expected Output

Please advise and let me know if this is possible. Thank you

CodePudding user response:

DECLARE @InString VARCHAR(200);
SET @InString='0130509667,0130509791,0130509824,0130509811,0130503549,0130503547,0130509323,0130509320,0130509145,0130509315';
SELECT VALUE FROM string_split(@InString,',');

CodePudding user response:

in sql server 2016 :

select y.value from tablename x
cross apply STRING_SPLIT(x.value,',') y
  • Related