sybase中的case语句

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

我对Sybase Query有以下要求: -

在下列情况下排除:

  • SSN有多于或少于九位数
  • SSN包含非数字字符
  • SSN是空白的
  • SSN包含相同的数字(例如,000000000,1111111111或999999999)
  • SSN的第一个数字为9,第四个数字为7,8或9
  • 第四和第五位数字是00(800-00-0000除外)
  • 第六到第九位数字是0000

我写了如下的案例陈述,但它不起作用,请有人帮忙请:

SELECT CASE
    WHEN LEN(a.MEMBER_SSN) > 9 THEN ' '
    WHEN LEN(a.MEMBER_SSN) < 9 THEN ' '
    WHEN LTRIM(RTRIM(a.MEMBER_SSN)) like '%[A-Z,a-z]%' then ' '
    WHEN LTRIM(RTRIM(WHEN a.MEMBER_SSN)) like '%[0-9]%' then ' '
    WHEN LTRIM(RTRIM(a.MEMBER_SSN)) in ( '000000000','000000001','000000002','000000003','000000004','000000005','999999999','111111111','000000070','123456789','999999998','000000071','888888888', ) THEN ''
    WHEN LTRIM(RTRIM(a.MEMBER_SSN)) NOT LIKE '9__[789]%' THEN a.MEMBER_SSN ELSE ' '
    WHEN LTRIM(RTRIM(a.MEMBER_SSN)) NOT LIKE '____[00]%' THEN a.MEMBER_SSN ELSE ' '
    WHEN LTRIM(RTRIM(a.MEMBER_SSN)) NOT LIKE '_____[0000]%' THEN a.MEMBER_SSN ELSE ' '
    END AS SUBSCRIBER_SSN From dbo.MEMBER_TABLE a
sql sybase case-statement
1个回答
0
投票

这是一个较短的版本:

SELECT (CASE WHEN LEN(a.MEMBER_SSN) <> 9 THEN ' '
             WHEN a.MEMBER_SSN LIKE '%[^0-9]%' THEN ' '
             WHEN REPLACE(a.MEMBER_SSN, LEFT(a.MEMBER_SSN, 1), '') = '' THEN ' '
             WHEN a.MEMBER_SSN LIKE '9__[789]%' THEN ' '
             WHEN a.MEMBER_SSN LIKE '___00%' AND a.MEMBER_SSN <> '800-00-0000' THEN ' '
             WHEN a.MEMBER_SSN LIKE '%0000' THEN ' '
             ELSE a.MEMBER_SSN
        END) AS SUBSCRIBER_SSN
From dbo.MEMBER_TABLE a

这几乎是你的条件的直接转录。

© www.soinside.com 2019 - 2024. All rights reserved.