1

但是,我构建了一个查询(见下文),而不是返回“大于 20 或 30”,我希望我的查询实际显示计数(例如 31、35、50 等)。我似乎无法弄清楚该怎么做。谢谢您的帮助。

select
cc_units_of_measure.description as UOM_Description, 
 case when LEN(cc_units_of_measure.description) < 20 then 'OK' 
 else 'Greater than 20' 
 end as Results_UOM_description,
 cc_units_of_measure.company_abbreviation as UOM_Company_Abbreviation, 
 case when LEN(cc_units_of_measure.company_abbreviation) < 20 then 'OK'
 else 'Greater than 20' 
 end as Results_UOM_company_abbreviation,
cc_frequencies.description as Freq_Description, 
 case when LEN(cc_frequencies.description) < 30 then 'OK' 
else 'Greater than 30' 
end as Results_Frequency_description
from cc_units_of_measure, cc_frequencies
4

1 回答 1

1

如果您更改 case 语句的 else 部分以返回长度,您将获得您正在寻找的值,如下所示:

SELECT  cc_units_of_measure.description AS UOM_Description ,
        CASE WHEN LEN(cc_units_of_measure.description) < 20 THEN 'OK'
             ELSE LEN(cc_units_of_measure.description)
        END AS Results_UOM_description ,
        cc_units_of_measure.company_abbreviation AS UOM_Company_Abbreviation ,
        CASE WHEN LEN(cc_units_of_measure.company_abbreviation) < 20 THEN 'OK'
             ELSE LEN(cc_units_of_measure.company_abbreviation)
        END AS Results_UOM_company_abbreviation ,
        cc_frequencies.description AS Freq_Description ,
        CASE WHEN LEN(cc_frequencies.description) < 30 THEN 'OK'
             ELSE LEN(cc_frequencies.description)
        END AS Results_Frequency_description
FROM    cc_units_of_measure ,
        cc_frequencies
于 2013-07-24T01:40:50.623 回答