我有如下表插入隨機數在SQL Server
create table MBR_IDS
(
MBR_SLNO int identity(1,1),
MBR_ID int
)
GO
ALTER TABLE MBR_IDS
ADD CONSTRAINT UNIQUE_MBR_ID
UNIQUE NONCLUSTERED (MBR_ID)
和下面的存儲過程創建一個隨機數
CREATE PROCEDURE USP_RANDOM_6
AS
BEGIN
DECLARE @chars NCHAR(36)
SET @chars = N''
DECLARE @result NCHAR(6)
SET @result = SUBSTRING(@chars, CAST((RAND() * LEN(@chars)) AS INT) + 1, 1)
+ SUBSTRING(@chars, CAST((RAND() * LEN(@chars)) AS INT) + 1, 1)
+ SUBSTRING(@chars, CAST((RAND() * LEN(@chars)) AS INT) + 1, 1)
+ SUBSTRING(@chars, CAST((RAND() * LEN(@chars)) AS INT) + 1, 1)
+ SUBSTRING(@chars, CAST((RAND() * LEN(@chars)) AS INT) + 1, 1)
+ SUBSTRING(@chars, CAST((RAND() * LEN(@chars)) AS INT) + 1, 1)
SELECT @result
END
GO
當我通過存儲過程中插入值:
declare @row int
set @row =1
while (@row <= 1000)
begin
insert into MBR_IDS
values(USP_RANDOM_6)
set @row = @row + 1
end
GO
我收到此錯誤:
感謝您幫助我很快..我不知道有關的輸出參數... – Nisar