I need to create a function that performs multiple replacements in a string based on a lookup table. However, the result is always the last replacement as if the previous replacements don't happen. The identical stored procedure provides the correct result.
Here is my function:
CREATE FUNCTION tmp.fix_template_list_data_test
(@source varchar(max))
RETURNS nvarchar(max)
AS
BEGIN
SELECT @source = REPLACE(@source, longer, shorter)
FROM tmp.vaccine_replacements
ORDER BY id
RETURN @source
END
This is on SQL Server.
1条答案
按热度按时间2nc8po8w1#
This works for me .
Proof:
The above
FUNCTION
usesCURSOR
-style logic with aWHILE()
loop - but that's okay because usingWHILE
is superior to aCURSOR
for situations like these .