数据透视表措辞 - SSMS 2012

时间:2013-04-16 16:16:52

标签: sql pivot sql-server-2012 ssms ssms-2012

我正在尝试转动表格的PRODUCT列。具有两个单词的值之间有下划线:

某些PRODUCT值的EX:

PRODUCT
USSIC_Aviation
Avemco_Aviation
Property
Life

这是我的透视代码:

select SIMULATION, [USSIC Aviation], [Avemco Aviation], [Property], [Life]
from CM.CorrelationData
pivot
(
min(Value)
for replace(PRODUCT,'_',' ') in ([USSIC Aviation], [Avemco Aviation], [Property], [Life])
) piv
where Product_Description='UW' 

它不喜欢replace(PRODUCT,'_',' '),但我不知道如何摆脱下划线。任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

您无法在查询的PIVOT区域中执行替换,因此您需要在子查询中执行它:

select SIMULATION, [USSIC Aviation], [Avemco Aviation], [Property], [Life]
from
(
  select SIMULATION, replace(PRODUCT,'_',' ') Product, value
  from  CM.CorrelationData
  where Product_Description='UW' 
) d
pivot
(
  min(Value)
  for PRODUCT in ([USSIC Aviation], [Avemco Aviation], [Property], [Life])
) piv