Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6026561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:27:48+00:00 2026-05-23T04:27:48+00:00

I have a test table like this CREATE TABLE #temp ( rid INT IDENTITY

  • 0

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;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:27:49+00:00Added an answer on May 23, 2026 at 4:27 am

    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 :

        DECLARE @t TABLE( randnum float )
    DECLARE @cnt INT; SET @cnt = 0
    WHILE @cnt <=10000
    BEGIN
    SET @cnt = @cnt + 1
    INSERT INTO @t
    SELECT RAND( (DATEPART(mm, GETDATE()) * 100000 )
    + (DATEPART(ss, GETDATE()) * 1000 )
    + DATEPART(ms, GETDATE()) )
    END
    SELECT randnum, COUNT(*)
    FROM @t
    GROUP BY randnum
    

    regards..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using MySQL 5 I have a table like this: date (varchar) door (varchar) shift
For example, I have a table which looks like this : id | name
Say I have this great query in my stored procedure. Select * from Temp
I may be going about this backwards... I have a class which is like
i got this Table: CREATE TABLE Test_Table ( old_val VARCHAR2(3), new_val VARCHAR2(3), Updflag NUMBER,
I have a sql file test.sql used to run some SQL (create object /
Consider the following data source: declare @Test table (EmpId int, ProdId int, Sold int)
I have test database and a production database. When developing I of course work
I've tryed mylyn but i cant find that feature, if anyone have test mantis
I have a test project using MbUnit and TestDriven.Net. If I right-click on an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.