案例陈述'不喜欢'可能吗?

时间:2013-10-21 14:11:10

标签: tsql

我希望将所有不是BA或BS的单身汉学位分开(例如BSAST)。我尝试了一个嵌套的case语句,但因为我对t-sql比较新,所以我不确定它是不是我的语法还是不可能。请注意,这是在select语句中。

SELECT
t2.ID,
t2.ACAD_PROGRAM,
'092013' AS T01,
'274842' AS T02,
REPLACE(p.SSN,'-','') AS T03,
'5' AS T04,
ap.ACPG_CIP AS T05,
CASE(t2.ACAD_PROGRAM)
  WHEN 'BA%' THEN '1'
  WHEN 'BS' THEN '2'
  ELSE (CASE
          WHEN t4.STP_DEGREE LIKE 'BA%'
          THEN '1' END)
END AS T06

1 个答案:

答案 0 :(得分:4)

CASE has two formats ,为了能够与LIKE operator一起使用,您的第一个CASE 应为Searched Case

SELECT t2.ID, t2.ACAD_PROGRAM, '092013' AS T01, '274842' AS T02, 
       REPLACE(p.SSN,'-','') AS T03, '5' AS T04, ap.ACPG_CIP AS T05, 
       CASE WHEN t2.ACAD_PROGRAM LIKE 'BA%' THEN '1' 
            WHEN t2.ACAD_PROGRAM = 'BS' THEN '2' 
       ELSE 
           CASE WHEN t4.STP_DEGREE LIKE 'BA%' THEN '1' END
       END AS T06
FROM yourTable