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 7511587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:35:44+00:00 2026-05-29T23:35:44+00:00

I am stuck on a query to generate a temporary table having values according

  • 0

I am stuck on a query to generate a temporary table having values according to the following condition.

I have a table as follows (Table1)

ID
1
5
9
3
10

I want a new record set according to the ID column value, like if I have ID=1, I need 1 row, if ID=5 I need five rows and so on in the temp table, so the out put table will look something like:

ID    Val
1     Null
5     Null
5     Null
5     Null
5     Null
5     Null

and so on..

I am using two loops to achieve this, one loop is through ID and inner loop through ID value, but I believe there must be a simpler way 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-05-29T23:35:46+00:00Added an answer on May 29, 2026 at 11:35 pm

    You could use a numbers table. Here I use spt_values that has a highest value of 2047. If that is not enough for you you should create a numbers table of your own.

    declare @T table(ID int)
    
    insert into @T values (1),(5),(9),(3),(10)
    
    select T.ID
    from @T as T
      inner join master..spt_values as N
        on N.number between 1 and T.ID
    where N.type = 'P'    
    order by T.ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm stuck with another coordinates related query here. I have a number of CSV
I'm stuck on a MDX query, I'm trying to retrieve the following results: [Time].[2009]
can anyone help?, i am stuck with a linq query.. basically i have a
I have a following HQL query: SELECT s.id FROM stack s WHERE s.category is
I'm stuck with a query I need to write. Given the following model: public
I have a problem where a bitwise operation on a query like the following
I'm stuck on a query with a join. The client's site is running mysql4,
I am stuck figuring out a working SQL Query for the fallowing: I need
I've been stuck with this simple Sql query for last 3 hours and my
I kind of stuck on how to implement this query - this is pretty

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.