1

In a table, I have a column like this:

Column

B1,B2,B3,...Bn

I want to split them like this:

Column1(B1), Column2 (B2), Column3 (B3)......Column N (Bn)

How to use SQL to split them? I know some articles discussed about this, for example:

T-SQL split string based on delimiter

However, in my situation, the number of strings which needs to split is not fixed, may be 3, maybe 30, or even bigger. How can we handle this?

Thanks,

Michael

Michael
  • 11
  • 1
  • Welcome to StackOverflow, Michael! There is no standard way to do what you want as normally tables have a fixed number of columns and a variable number of rows. What kind of database are you using? There may be a way in your database. To do this, one would normally not insert a delimited list into a single database column - instead one would create an additional table with one row per value in the list and linked via a foreign key constraint to the original table. – Simon G. Aug 12 '20 at 18:51
  • Which RDBMS are you using? – dougp Aug 12 '20 at 19:05
  • sounds like you need to use dynamic sql meaning you dynamically generate the sql string that will be run beforehand and then run it. You can do this in stored procedure. Google "stored procedure" and "dynamic sql", dive into it a few days and you should be a lot smarter and have a working solution. – Griffin Aug 12 '20 at 21:33

0 Answers0