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:
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.
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:
Code:
SELECT col,value
FROM
(SELECT DISTINCT ColumnName
FROM tblMapping
WHERE TableName = 'Product') p
UNPIVOT
(ColumnValue FOR ColumnName IN (SELECT DISTINCT ColumnName
FROM tblMapping
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.