0

我正在尝试旋转表的 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,'_',' ')但我不知道如何摆脱下划线。任何帮助将不胜感激!

4

1 回答 1

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
于 2013-04-16T18:40:15.333 回答