1

我正在寻找所有不是 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
4

1 回答 1

4

CASE 有两种格式,为了能够使用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
于 2013-10-21T14:16:46.310 回答