SQL语句时多个Case

时间:2017-11-08 05:26:52

标签: sql-server case isnull case-when

我正在尝试执行以下查询。

SELECT
ABL.Address1 AS BillingAddress1,
ABL.Address2 AS BillingAddress2,
ABL.Address3 AS BillingAddress3,
ABL.Address4 AS BillingAddress4,
ABL.UnitNumber AS BillingUnitNumber,
ABL.City AS BillingCity,
ABL.ProvinceOrState AS BillingProvinceOrState,
ABL.PostalCode AS BillingPostalCode,
CASE ISNULL (ABL.CountryCode,'')
                                WHEN 'CAN' THEN 'CANADA'
                                WHEN 'CA' THEN 'CANADA'
                                WHEN 'US' THEN 'USA'    
                                WHEN '' THEN
CASE WHEN CHARINDEX(RTRIM(ABL.ProvinceOrState),'BC,NWT,SK,MB,ON,QC,NB,NS,PEI,NF')>0                                                                                THEN 'CANADA'                                                                    ELSE NULL                                                                              END
ELSE ABL.CountryCode                
END AS BillingCountryCode

但它抛出了以下错误。

  

Msg 102,Level 15,State 1,Line 85语法不正确&#39 ;;'。

我无法找到查询的错误。

2 个答案:

答案 0 :(得分:2)

您有编码Locale.currency["US"] // (code "USD", symbol "US$") Locale.currency["BR"] // (code "BRL", symbol "R$") Locale.currency["GB"] // (code "GBP", symbol "£") Locale.currency["PT"] // (code "EUR", symbol "€") 而不是>:

>

答案 1 :(得分:1)

我看到案例陈述中有一个文字& gt; 而不是>

SELECT
ABL.Address1 AS BillingAddress1,
ABL.Address2 AS BillingAddress2,
ABL.Address3 AS BillingAddress3,
ABL.Address4 AS BillingAddress4,
ABL.UnitNumber AS BillingUnitNumber,
ABL.City AS BillingCity,
ABL.ProvinceOrState AS BillingProvinceOrState,
ABL.PostalCode AS BillingPostalCode,
CASE ISNULL (ABL.CountryCode,'')
                                WHEN 'CAN' THEN 'CANADA'
                                WHEN 'CA' THEN 'CANADA'
                                WHEN 'US' THEN 'USA'    
                                WHEN '' THEN
CASE WHEN CHARINDEX(RTRIM(ABL.ProvinceOrState),'BC,NWT,SK,MB,ON,QC,NB,NS,PEI,NF') > 0                                                                                THEN 'CANADA'                                                                    ELSE NULL                                                                              END
ELSE ABL.CountryCode                
END AS BillingCountryCode

试试这个 - 我刚刚更换了字符串“& gt;”使用> 符号

当您从任何其他窗口或文本编辑器复制代码时,可能会发生这种情况