在table1中,列的数据类型如下,category2 VARCHAR2(20 CHAR)我希望通过使用unpivotselectCATEGORY, from table1 REASON for CATEGORY in(catgory1,category2,category3)当我试图执行这个查询时,它会显示以下错误,
表达式必须具有与相应表达式相
select reportruncaseid, year(Ecodate) as EcoYear, val, col
unpivotState 1, Line 10 The type of column "EcoDate" conflicts with the type of other columns specified in the UNPIVOT
我需要从单个表的10+列中提取一列数据。与其堆叠10+联合select语句,还有其他方法可以做到这一点而不重复每个列的union语句吗?select 'column_5' from table_aselect 'column_6' from table_a select 'column_7' from table_a..select 'column_18' from table_a
(谢谢你提前抽出时间:
有没有更好(更有效)的方式来写这个查询?似乎应该有一种只用一个UNION来编写它的方法。SELECT 'Value1' as PropertyKey, PropertyValue=(SELECT Value1 FROM MyTable WITH (NOLOCK))SELECT 'Value2' as PropertyKey, PropertyValue=(SELECT Value2 FROM MyTable WITH (NOLOCK))SELECT 'Value3' as PropertyKey, Prope
但是,对于所有列,数据类型的长度并不相同。我这么说是因为当我使用LTRIM和RTRIM时,它会出现一个错误“--列的类型”"SubscriberLastName“与UNPIVOT list中指定的其他列的类型发生冲突”,如果我强制转换该列,则没有结果CorrectValue' end as [SubscriberFirstName] Unpivot
我有一个查询,它返回一行数据。假设它看起来像这样(带有列标题)。编辑:查询返回非静态的结果,因此我无法显式定义列标题。SELECT FieldName,FROM Meter M
UNPIVOT来自原始表的转换结果不能工作,因此我必须使用派生表并在那里进行强制转换,以便返回到PIVOT的列都是相同的数据类