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

  • SEARCH
  • Home
  • 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 9164637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:43:51+00:00 2026-06-17T14:43:51+00:00

I have two tables as following. ‘Areas’ Table | AreaKey | AreaID | |—————–|————–|

  • 0

I have two tables as following.

‘Areas’ Table

|    AreaKey      |    AreaID    |
|-----------------|--------------|
| <identity/int>  |  <varchar>   |

‘Readings’ Table

|    ReadingKey   |      AreaKey      |   Reading   |    ReadingDateTime   |
|-----------------|-------------------|-------------|----------------------|
| <identity/int>  |<FK:AreaKey-Areas> |   <float>   |      <datetime>      |

  • ‘AreaKey’ in Readings table is a foreign key to ‘AreaKey’ of Areas table.

Areas table already have some data with row id’s ranging from 1 to 50.

I want to populate the Readings table with some sample data – (random float values for ‘Reading’ column between 1.0 and 100.0 AND a random datetime value for ReadingDateTime between a given DateTime range; for example between current datetime and a datetime 3 months back). These values should be inserted to the Reading table by randomly selecting AreaKeys which already exist in the Areas table.

In other words I want to insert random reading values to randomly selected areas, with random datetimes.

Can anyone give me a clue on how to do this?

  • 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-06-17T14:43:52+00:00Added an answer on June 17, 2026 at 2:43 pm

    Assuming your Areas table has 50 records, with row ids 1-50, I would just look into using the RAND function.

    Something like this seems to work:

    SELECT ROUND(((50 - 1 -1) * RAND() + 1), 0) as AreakKey,
        ROUND(((100 - 1 -1) * RAND() + 1), 1) as Reading,
        DATEADD(mm,-3,GETDATE()) +
    (
    ABS(
        CAST(
            CAST( NewID() AS BINARY(8) ) AS INT
        )
    )
    %
    CAST(
        (GETDATE() - DATEADD(mm,-3,GETDATE())) AS INT
        )
    ) as ReadingDateTime   
    

    And here’s some SQL Fiddle.

    Good luck.

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

Sidebar

Related Questions

I have two tables defined as the following: User (ID int, name varchar) Hours
I have two tables with the following (simplified) structures: table "Factors" which holds data
I have two database tables with the following structure: actions: action_id int(11) primary key
I have two tables with the following schema: CREATE TABLE sales_data ( sales_time date
I have two tables that look like following: RELEASE TABLE name asin MATCHES TABLE
I have following two tables in the database. One table is person table and
I have this following problem: I have two tables 1 table for customer bought
I have two tables. One table is called Occurrence that contains the following: OccurrenceID
I have two tables with the following: table 1 sid, schedule, stime, splace, stourid
I have following two tables Table name: thread pk-> thread_id | thread_title | description

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.