-2

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

Charlieface
  • 52,284
  • 6
  • 19
  • 43
SQL Rookie
  • 11
  • 4
  • Please read [this](https://spaghettidba.com/2015/04/24/how-to-post-a-t-sql-question-on-a-public-forum/) for some tips on improving your question. – HABO Oct 08 '21 at 17:54
  • Does this answer your question? [Turning a Comma Separated string into individual rows](https://stackoverflow.com/questions/5493510/turning-a-comma-separated-string-into-individual-rows) – Charlieface Oct 09 '21 at 20:29

2 Answers2

0
DECLARE @InString VARCHAR(200);
SET @InString='0130509667,0130509791,0130509824,0130509811,0130503549,0130503547,0130509323,0130509320,0130509145,0130509315';
SELECT VALUE FROM string_split(@InString,',');
Sergey
  • 4,719
  • 1
  • 6
  • 11
0

in sql server 2016 + :

select y.value from tablename x
cross apply STRING_SPLIT(x.value,',') y
eshirvana
  • 23,227
  • 3
  • 22
  • 38