Hi, I had the following query in my sql.
select C.name from sys.columns c where c.object_id = OBJECT_ID('TRANSACTIONS.T_Transaction') DECLARE @colsUnpivot AS NVARCHAR(MAX), @query AS NVARCHAR(MAX), @table As Varchar(50) = 'TRANSACTIONS.T_Transaction' select @colsUnpivot = stuff((select ','+ convert(varchar(50), quotename(C.name)) FROM sys.columns c WHERE c.object_id = OBJECT_ID(@table) for xml path('')), 1, 1, '') set @query = 'select data from ' + (@table) + ' unpivot ( data for d in ('+ @colsunpivot +') ) u' exec sp_executesql @query;
However I get the following error when trying to execute:
The type of column "Company_ID" conflicts with the type of other columns specified in the UNPIVOT list.
May i know how can I amend my query?