I have seen a few answers on how to convert rows to columns but they are rather specific to the questions and are difficult for me to transpose into my own solution.
The data starts out as a varchar, but I convert it to XML because I thought it would be easier to convert it to columns that way.
-- get xml
DECLARE @x XML
SET @x = '<ul><li>Gas grill rotisserie</li><li>Fits the Genesis E-300 gas grill</li><li>Fits the Genesis S-300 gas grill</li><li>Includes a heavy-duty electric motor</li><li>Counterbalance for smooth turning and less motor wear</li></ul>'
SELECT x.r.value('node()[1]','varchar(200)')
FROM @x.nodes('/ul/li') AS x(r)
This returns a results like the following; however, I now need to convert each row into a column.
I have tried variations using pivot and dynamic SQL, but haven't gotten very far. How can I convert each row to a column (when the number of rows will be unknown).
Ref. Convert Rows to columns using 'Pivot' in SQL Server Ref. How to convert row values to columns with dynamic columns count?