I have created a function with PIVOT
that turns the string into table which is the output I want. What I want is I don't need to declare the columns one by one.
Here's the code:
SELECT
Name1, Name2, Name3
FROM
(
SELECT
LEFT(CA.val,CHARINDEX('=',CA.val)-1) ColumnName,
SUBSTRING(CA.val,CHARINDEX('=',CA.val)+1,100) Value
FROM Z_SampleTable
CROSS APPLY dbo.SplitSample(ProcessBody,'|') CA
) PD
PIVOT
(
MAX(Value)
FOR ColumnName IN (Name1, Name2, Name3)
)
AS PT
Is there a way that doesn't need to declare each column? For example, I have a table that contains 100 columns, is there a way not to declare those 100 columns?