小编Gri*_*fin的帖子

从字符表递归替换

简而言之,我正在寻找可以对一个字符串执行多次替换的单个递归查询。我有一个想法是可以做到的,但我无法理解它。

当然,我更喜欢应用程序的商业层,甚至是 CLR,来进行替换,但在这种情况下,这些不是选项。

更具体地说,我想用 TVF 替换下面的混乱 - 这是 8 个不同存储过程中的 C&P。

SET @temp = REPLACE(RTRIM(@target), '~', '-')
SET @temp = REPLACE(@temp, '''', '-')
SET @temp = REPLACE(@temp, '!', '-')
SET @temp = REPLACE(@temp, '@', '-')
SET @temp = REPLACE(@temp, '#', '-')
-- 23 additional lines reducted
SET @target = @temp
Run Code Online (Sandbox Code Playgroud)

这是我开始的地方:

-- I have a split string TVF called tvf_SplitString that takes a string 
-- and a splitter, and returns a table with one row for each element.
-- EDIT: …
Run Code Online (Sandbox Code Playgroud)

t-sql recursion sql-server-2005

4
推荐指数
2
解决办法
4015
查看次数

标签 统计

recursion ×1

sql-server-2005 ×1

t-sql ×1