我一直在尝试将以下SQL代码转换为CASE - WHEN到SSIS派生列表达式。该表达式将使用varchar(5)数据类型进入新列。
SQL代码:
CASE
WHEN SUBSTRING(A.Column1,1,5) = 'John'
OR
(C.Column1 IS NOT NULL
AND A.Column2 = 'Two')
THEN 'Two'
WHEN SUBSTRING(A.Column1,1,5) = 'Mike'
THEN 'HD'
WHEN D.Column1 IS NOT NULL
AND F.Column1 IS NOT NULL
AND G.Column1 LIKE '%DDD%'
AND G.Column2 = H.Column1
AND H.Column2 = '1'
AND H.Column3 = 'Y'
AND H.Column4 <= A.Column3
AND H.Column5 > A.Column3
AND H.Column6 <= A.Column3
THEN 'HE'
WHEN B.Column1 IS NOT NULL
THEN ''
WHEN E.Column1 IS NOT NULL
THEN '22'
ELSE ''
我的表达:
SUBSTRING([A.Column1],1,5) == "John"
|| (ISNULL([C.Column1]) == FALSE
&& ([A.Column2] == "Two") ? "Two":
(SUBSTRING([A.Column1],1,5) == "Mike" ? "HD":
(ISNULL([D.Column1]) == FALSE
&& ISNULL([F.Column1]) == FALSE
&& FINDSTRING([G.Column1], "DDD",1) > 0
&& [G.Column2] ==[H.Column1]
&& [H.Column2] == "1"
&& [H.Column3] == "Y"
&& [H.Column4] <= A.Column3
&& [H.Column5] > A.Column3
&& [H.Column6] <= A.Column3 ? "HE":
(ISNULL([B.Column1]) == FALSE ? "":
(ISNULL([E.Column1]) == FALSE ? "22":""
))))
我是建立表达方式的新手,并且无法找到我出错的地方。我无法下载Expression Tester软件,因为我无法在工作计算机上运行.exe。非常感谢任何帮助。
答案 0 :(得分:0)
你在之前缺少一个结束括号吗? &#34;两个&#34;:强>
试试这个:
SUBSTRING([A.Column1],1,5) == "John"
|| (ISNULL([C.Column1]) == FALSE
&& ([A.Column2] == "Two")) ? "Two":
(SUBSTRING([A.Column1],1,5) == "Mike" ? "HD":
(ISNULL([D.Column1]) == FALSE
&& ISNULL([F.Column1]) == FALSE
&& FINDSTRING([G.Column1], "DDD",1) > 0
&& [G.Column2] ==[H.Column1]
&& [H.Column2] == "1"
&& [H.Column3] == "Y"
&& [H.Column4] <= A.Column3
&& [H.Column5] > A.Column3
&& [H.Column6] <= A.Column3 ? "HE":
(ISNULL([B.Column1]) == FALSE ? "":
(ISNULL([E.Column1]) == FALSE ? "22":""
))))