SQL Server 2008 R2 - Scalar UDF results in infinite loop
问题 The following code is resulting in an infinite loop or really really slow execution: CREATE FUNCTION [dbo].[CleanUriPart] ( -- Add the parameters for the function here @DirtyUriPart nvarchar(200) ) RETURNS nvarchar(200) AS BEGIN; -- Declare the return variable here DECLARE @Result nvarchar(200); DECLARE @i int; SET @i = 1; WHILE 1 = 1 BEGIN; SET @i = PATINDEX('%[^a-zA-Z0-9.~_-]%', @DirtyUriPart COLLATE Latin1_General_BIN); IF @i > 0 SET @DirtyUriPart = STUFF(@DirtyUriPart, @i, 1, '-'); ELSE