for a totally different way you could to this. It assumes you have some type of UNIQUE constriant on UserID (which you should)declare @id varchar(64) ,@i int ,@errorstate intset @id = 'this is the user id'set @i = 0while @i = 0 OR @errorstate is not nullbegin begin try insert usertest (userid) select @id + isNull(convert(varchar(12), nullif(@i, 0)),'') set @errorstate = null end try begin catch set @errorstate = error_state() set @i = @i+1 end catchend
Be One with the OptimizerTG