I have a table structure (tblmapping) like the following:
TableName ColumnName ColumnValue
Product ProductID 1
Product ProductID 2
Product ProductName Keyboard
Product ProductName Mouse
I want to convert from column based data to row based data. I tried the following query, but syntax errors:
(SELECT DISTINCT ColumnName
WHERE TableName = 'Product') p
(ColumnValue FOR ColumnName IN (SELECT DISTINCT ColumnName
WHERE TableName = 'Product')
) AS unpvt;
Msg 156, Level 15, State 1, Line 7
Incorrect syntax near the keyword 'SELECT'.
Msg 102, Level 15, State 1, Line 9
Incorrect syntax near ')'.
Not sure what I'm doing wrong. Thanks for the help.