我有一个庞大的(政府)地址数据库,没有经过验证,因此需要对某些字符串进行批量查找/替换。例如,我想用“st”替换“str”,用“ave”替换“aven”。我想用一个函数来做这个,就像下面我从另一个网站得到的函数一样
-- Input: Red, Blue, Green
-- Output: RGB
SELECT
s.Colors
FROM
(SELECT 'Red, Green, Blue' AS Colors) c
CROSS APPLY (SELECT REPLACE(c.Colors,'Red','R') AS Colors) r
CROSS APPLY (SELECT REPLACE(r.Colors,'Green','G') AS Colors) g
CROSS APPLY (SELECT REPLACE(g.Colors,'Blue','B') AS Colors) b
CROSS APPLY (SELECT REPLACE(b.Colors,', ','') AS Colors) s
不幸的是,我的格式化知识很薄弱,所以我尝试将此应用于此查询都失败了。
SELECT QICISFacilities.[Programmatic ID], QICISFacilities.[Site Name], QICISFacilities.Address
FROM (SELECT QICISFacilities) c
CROSS APPLY (SELECT REPLACE (c.address, 'STR','ST') AS Address);
我得到“语法错误从请求”,我不知道我在做什么,请帮助。
暂无答案!
目前还没有任何答案,快来回答吧!