Auerelio Vasquez
asked on
Get data between commas
Hi
I have data like this
Id Products
1 Product1;product2
Separate by semi colon
I'd like the data like this
1 product1
1 product2
Etc
I have data like this
Id Products
1 Product1;product2
Separate by semi colon
I'd like the data like this
1 product1
1 product2
Etc
ASKER
This is a bit difficult to follow. Can you do it from the perspective that product is the column name and there may be more than one product in the column. Also Id is not always 1
It may be like this
ID Products
1 Prod1, prod2, product3, prodn
2./
It may be like this
ID Products
1 Prod1, prod2, product3, prodn
2./
ASKER
Sorry I'd like the outcome to look like this
1 product1
1 product2
2 product3
2 product4
1 product1
1 product2
2 product3
2 product4
ASKER
By the way products is a column in a table called events.
So I want to solution to use the table and column name
So I want to solution to use the table and column name
Hopefully you already have a script for a split function.
You can query it as follows:
You can query it as follows:
select Id, s.data
from events e
outer apply dbo,split(e.Products, ',') s
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SQL Server 2008 -
Open in new window
Here's a reference - http://www.sqlservercentra
In SQL server 2016 there are inbuilt functions for splitting a string so you could try this code -
Open in new window