在 SSIS 中转换 SQL Case 语句

问题描述 投票:0回答:1

我尝试创建一个 SSIS 包来取消透视表。 unpivot 工作正常。然而,我遇到的问题是原始 sql 包含两个 case 语句,我似乎无法让它将结果输出到派生列。不确定派生列是否可行。

这是原始 SQL:

    SELECT reading_no
      ,[time] as sample_date_stamp
      ,[type]
      ,[units]
      ,[Parameter] as analyte
      ,[value] as results
      ,case when substring([VALUE],1,1) not in ('<','') then cast(VALUE as decimal) end as result_fixed
      ,case when substring([VALUE],1,1) in ('<','') then 1 else 0 end as results_ltd
    FROM TEMP

这是示例数据:

reading_no  sample_date_stamp           type    units   analyte results  result_fixed   result_LTD
2002        2022-04-04 12:10:00.0000000 Soil    ppm     AG      9.52     10             0
2003        2022-04-04 12:39:00.0000000 Soil    ppm     AG      NULL NULL               1
2004        2022-04-04 12:42:00.0000000 Soil    ppm     AG      < LOD     NULL          1
2005        2022-04-04 16:30:00.0000000 Test    ppm     AG      < LOD     NULL          1

我需要在包中的某个位置使用派生列转换来解释 case 语句。目前,在对表进行逆透视并尝试使用表达式来转换 Case 语句后,我获得了 DCT。我在派生列中对 case 语句使用了以下表达式:

FINDSTRING( [RESULTS] ,"<", 1)) == 0 ?  (DT_DECIMAL, [RESULTS])
FINDSTRING( [RESULTS] ,"<", 1)) != 0 ?  (DT_DECIMAL,"1") : (DT_DECIMAL,"0") 

出现以下错误:

数据流任务 1 [派生列 [1182]] 出错:尝试解析表达式“FINDSTRING( [RESULTS] ,”<", 1) == 0 ? (DT_DECIMAL, [RESULTS])" failed. The expression might contain an invalid token, an incomplete token, or an invalid element. It might not be well-formed, or might be missing part of a required element such as a parenthesis.

提前致谢..

ssis unpivot derived-column
1个回答
0
投票

我相信你的问题是这个表达

(DT_DECIMAL,"1") : (DT_DECIMAL,"0")

不要将音阶包裹在字符串中

(DT_DECIMAL,1) : (DT_DECIMAL,0)
© www.soinside.com 2019 - 2024. All rights reserved.