-1

Ex.

SELECT A_NUM, [No. of Entries], Address  
FROM Table_1

Output:

123222, 5, 'MNL'
122334, 6, 'GS'

Then insert this data into another table.

INSERT INTO Table_entries 
VALUES ('123222', 'MNL') 

should run 5 times based on the no of entries. (6 times for '122334', 'GS')

Thank you.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    Possible duplicate of [Run insert statement x number of times](https://stackoverflow.com/questions/13476598/run-insert-statement-x-number-of-times) – CodeCaster Jan 26 '18 at 07:25
  • @CodeCaster can you post the query for my concern? i read the link you provided i think we have a different scenario, thanks – Byron Louise Hudkin Festin Jan 26 '18 at 07:29
  • Are you trying to *populate* a table (or result set) with a particular number of rows (what I get from the question body) or *constrain* the number of rows that the second table can contain (what I get from the question title)? – Damien_The_Unbeliever Jan 26 '18 at 07:32
  • Sounds like you want to SELECT, JOIN, and INSERT. If so, that can be done. – James A Mohler Jan 26 '18 at 07:34
  • @Byron perhaps try reading the answers, and not dismissing the link based on the question. The `CROSS APPLY` solution is also mentioned in the duplicate. – CodeCaster Jan 26 '18 at 08:36

1 Answers1

0

Consider using a CROSS JOIN of some large tables like this

insert into table_entries
select t1.a_num, t1.address 
from table1 t1
cross apply (
    select top (t1.no) 1 
    from sys.sysobjects 
    cross join sys.all_columns
) t(n)

dbfiddle demo

CROSS JOIN can be possibly replaced by some sequence generator.

Radim Bača
  • 10,646
  • 1
  • 19
  • 33