I have a test table like this
CREATE TABLE #temp (
rid INT IDENTITY (1, 1) NOT NULL,
val INT NULL,
CONSTRAINT pk_temp_rid PRIMARY KEY (rid)
);
What are the different methods in SQL Server to insert random integers into this table (e.g for 1000 rows). While loop, cross join or what?
I tried this but the result is not correct
DECLARE @val AS INT = 1;
WHILE @val <= 1000
BEGIN
INSERT #temp (val)
SELECT RAND(@val);
SET @val = @val + 1;
END
SELECT *
FROM #temp;
you can use
select CAST(RAND() * 1000000 AS INT) AS [RandomNumber]for generating or selecting random integers .so the full query will be something like that :
regards..