This is running into an infinite loop... Any ideas? It just runs and runs...


USE [UOS1]
GO

/****** Object:  UserDefinedFunction [dbo].[makePictureName]    Script
Date: 04/19/2012 14:13:22 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER FUNCTION [dbo].[makePictureName]
   (@s varchar(256),
   @id int)
RETURNS varchar(50) AS
BEGIN
   declare @finalText varchar(256)
   declare @origText varchar(256)
   declare @i int
   declare @j int
   declare @k int

   select @s = replace(@s,' - ',' ')
   select @i = patindex('%[^a-zA-Z0-9 ]%', @s)
   while @i > 0
   begin
       select @s = replace(@s, substring(@s, @i, 1), '')
       select @i = patindex('%[^a-zA-Z0-9 ]%', @s)
   end
   set @finalText =  lower(replace(@s,' ','-'))
   set @finalText = left(@finalText,46)
   set @origText = @finalText
   set @j = 1
   set @k = 1

   while @j > 0
   begin
   set @j = (select count(*) from item where picturename = @finalText
+ '.jpg' AND id <> @id)
   if (@j > 0) set @finalText = @origText + cast(@k as varchar(3))
   set @k = @k + 1
   end

   return @finalText + '.jpg'
END
GO

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-community/message.cfm/messageid:350141
Subscription: http://www.houseoffusion.com/groups/cf-community/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-community/unsubscribe.cfm

Reply via email to