I have table tb1(col1, col2), col2 is varchar(50). For instance,
col1 col2
item1 abc
item2 a
item3 ed
I want to write a stored procedure to parse col2 and create a temp table like following:
col1 col2
item1 a
item1 b
item1 c
item2 a
item3 e
item3 d
Can anybody help me out here?
If you know the maximum length of the string, the easiest way is doing a simple union:
If the length is never too long, you can do something like this to simplify the query:
Alternatively, you can do this in a while loop in T-SQL.