Given a Promotion table with rows and data such as:
PromotionId Codes
1 a,b
2 c
3 d,e,f
How could I write a query to return it like this:
PromotionId Codes
1 a
1 b
2 c
3 d
3 e
3 f
Basically I want to string split the Code over multiple rows.
You can use a
Splittable-valued-function, for example:Then you can use
CROSS APPLYto join with it:Edit: Here’s a fiddle with your data: http://sqlfiddle.com/#!3/85f8b/1/0
Result: