我必须过滤字符串列中的数据,因此需要将使用的列NOT LIKE
与一堆字符串进行比较。
我正在使用 SQL Server,我的代码如下所示:
SELECT history.date,
history.new_value,
res.resource_name
FROM item_history history,
owned_resource res
WHERE (history.attr_name = 'resource_contact' OR history.attr_name = 'Kontakt-UUID')
AND res.inactive = 0
AND history.com_par_id = res.own_resource_uuid
AND lower(history.new_value) NOT LIKE '%tp für%'
AND lower(history.new_value) NOT LIKE '%rücklieferung%'
AND lower(history.new_value) NOT LIKE '%rückläufer%'
AND lower(history.new_value) NOT LIKE '%stoerreserve%'
AND lower(history.new_value) NOT LIKE '%zentrallager%'
AND lower(history.new_value) NOT LIKE '%bhs-pool%'
AND lower(history.new_value) NOT LIKE '%lager halle%'
AND lower(history.new_value) NOT LIKE '%lager logistik%'
AND lower(history.new_value) NOT LIKE 'reserve %'
AND lower(history.new_value) NOT LIKE '%igeko%bhs%'
AND lower(history.new_value) NOT LIKE '%service%ecg%'
AND lower(history.new_value) NOT LIKE '%multifunktionsdrucker%'
AND lower(history.new_value) NOT LIKE 'nn%gisa%raum%'
AND lower(history.new_value) NOT LIKE '%citrix%admins%'
AND lower(history.new_value) NOT LIKE '%personalwesen%'
AND lower(history.new_value) NOT LIKE '%etagendrucker%'
AND lower(history.new_value) NOT LIKE '%schulungsraum%'
AND lower(history.new_value) NOT LIKE '%team%raum%'
AND lower(history.new_value) NOT LIKE '%beratungsraum%'
AND lower(history.new_value) != 'reserve'
)
我猜性能并不是一遍又一遍地调用“lower()”的最佳方法。另外,作为一名程序员,看到这么多冗余代码,我的指甲都卷起来了。不幸的是,我没有找到使用变量或其他东西的好方法。(我想补充一点,我不能简单地添加一个新的计算列,这将是一个好方法,我只被授权读取数据。)
有什么建议可以让代码更智能吗?