我构建了一个查询(见下文)但是,我没有返回“大于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
答案 0 :(得分: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