ALTER PROC Proc_RandString @length INT, @RandString char(1000) OUTPUT AS BEGIN DECLARE @String char(1000) SELECT @String = NULL IF (@length < 0) OR (@length IS NULL) BEGIN RETURN 0 END ELSE IF @length = 0 BEGIN SELECT @length = CONVERT(INT,RAND()*1000)%1000 END SET @String = CHAR((CONVERT(int,RAND()*1000)%24)+65) WHILE (@length > 1) BEGIN SET @String = @String + char(CONVERT(int,RAND()*1000)%24+65) SELECT @length = @length - 1 SELECT @length,@String END SELECT @RandString = @String SELECT @RandString RETURN 1 END DECLARE @CHAR VARCHAR(1000) EXEC Proc_RandString @length = 10,@RandString = @CHAR OUTPUT SELECT @CHAR