我有一个varchar(200)列,其中包含诸如,
ABC123124_A12312
ABC123_A1212
ABC123124_B12312
AC123124_AD12312
A12312_123
等等..
我想用一个数字替换一个数字序列,*
以便我可以对表格中的不同非数字模式进行分组。
这个集合的结果是
ABC*_A*
ABC*_B*
AC*_AD*
A*_*
我在下面编写了以下原始查询,它可以正常工作,但是在一张大表上运行需要很长时间。
我需要帮助重写或编辑它以提高它的性能。SQL Server 2014
-- 1. replace all numeric characters with '*'
-- 2. replace multiple consecutive '*' with just a single '*'
SELECT REPLACE
(REPLACE
(REPLACE
(REPLACE
(REPLACE
(REPLACE
(REPLACE
(REPLACE
(REPLACE
(REPLACE
(REPLACE
(REPLACE
(REPLACE(SampleID, '0', '*'),
'1', '*'),
'2', '*'),
'3', '*'),
'4', '*'),
'5', '*'),
'6', '*'),
'7', '*'),
'8', '*'),
'9', '*')
, '*', '~*') -- replace each …
Run Code Online (Sandbox Code Playgroud) sql-server pattern-matching sql-server-2014 string-manipulation query-performance
sql-server ×1