我需要创建一个给定长度的随机数字字符串
CREATE FUNCTION UniqConvert
(@calue as varchar(max),
@len as int)
输出应该是长度@len
并且每个输入应该是唯一的@value
我已经问过类似的问题: Create random string of digits T-SQL This one has different concept
我需要创建一个给定长度的随机数字字符串
CREATE FUNCTION UniqConvert
(@calue as varchar(max),
@len as int)
输出应该是长度@len
并且每个输入应该是唯一的@value
我已经问过类似的问题: Create random string of digits T-SQL This one has different concept
尝试这个
select Cast(Round(Rand()*power(10,@Len),0) as Varchar(30))
declare @len int
set @len = 3
DECLARE @Random INT
DECLARE @Upper INT
DECLARE @Lower INT
SET @Lower = power(10,@Len-1) ---- The lowest random number
SET @Upper = power(10,@Len )-1 ---- The highest random number
SELECT @Random = ROUND(((@Upper - @Lower -1) * RAND() + @Lower), 0)
select @Random