Case-insensitive REPLACE() in SQL Server 2000

拟墨画扇 提交于 2019-12-05 07:03:23

Use a case insensitive collation:

SELECT field as "before", REPLACE(field COLLATE SQL_Latin1_General_Cp1_CI_AI
, 'OVER', '') as "after"

See COLLATE for list of collation names so you choose the one appropiate for your data.

Update

Ok, so I missed your actual request (change case of input, not find case-insensitive). The proper solution is... not to change the input but use an adequate collation for your data. If the data must be displayed in a specific format, use display options in the client, eg. CSS text-transform:uppercase, not in the server SELECT.

There isn't any built-in SQL function to do this transformation in-place, but is trivial to build a CLR function that uses RegEx. (On SQL 2005, not on SQL 2000... doh, I need more coffe).

I'm not familiar with SQL Server, but maybe it allows you to make use of regular expressions. These usually offer a case-insensitive mode (set via the i-flag).

Otherwise you could uppercase before the replace call, e.g.

SELECT field as "before", REPLACE(UPPER(field), 'OVER', '') as "after"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!