Adding rows to a table based on number in another row

Neo

I receive data from our customers which we load into a work table. The data consists of address fields, order number, etc One of the columns contains the start range for a serial number. Another column is a quantity.

What we need to do is move the initial data row from one table to another and insert additional rows incrementally corresponding to the quantity column.

The starting number is the last 4 digits of the serial number and we need to add rows to the table.

So if the last 4 digits of the serial number are 2350 and the quantity is 10, we need to add the additional rows 9 with the last 4 digits of the serial number incremented by 1, like this 2351, 2352, 2353, etc.

Any guidance would be appreciated.

Jon

For MS SQL Server you could use this SQL snippet, and modify for your own table schema

declare @LastFour int = 2350
declare @Quantity int = 10
declare @Current int = 1

while @Current <= @Quantity
begin
  insert into MyOrders (OrderID, ...) values (@LastFour + @Current)
  set @Current = @Current + 1
end
go

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SQL - Delete row based on number of rows in another table

From Dev

Adding missing rows from the another table based on 2 columns

From Dev

Insert multiple rows in one table based on number in another table

From Dev

select data.table R rows based on row number and condition

From Dev

Sqlite - Update table rows based on another data in the row

From Dev

SQL Hide/Show rows based on row count from another table

From Dev

Excel adding rows based on if they are a number

From Dev

Adding multiple rows of a table to another table

From Dev

How to use PHP to query MySQL for certain rows, then for each row, based on a UID, query another table based on value?

From Dev

SQL - Need to update a value in a table based the number of relations its row has to another table

From Dev

Adding/Deleting table rows based on Select value

From Dev

adding multiple rows in mysql table based on an array

From Dev

Expanding query table rows based on another table

From Dev

Adding a Row Number to a Temp Table in Stored Procedure

From Dev

Compare two table and adding row based on condition

From Dev

JQuery Adding new Row in Table based on Selection

From Dev

Compare two table and adding row based on condition

From Dev

Adding empty number of rows in gridview based on grid rows count

From Dev

Select rows according row type in another table

From Dev

Select rows with show flag but based on another table

From Dev

MySQL - Query For Rows With Updates Based On Another Table

From Dev

Searching for number of values in one table, resizing number of rows in another table

From Dev

insert a row in 3 tables when adding another row for a new table

From Dev

Matlab adding rows to a table from another table with different dimensions

From Dev

R - fill rows of a column down based on another row in another column

From Dev

How to add certain number of rows based on values on the rows of another variable

From Dev

Adding rows from one IEnumerable to another based on conditions

From Dev

Adding multiple cells in a column based on a value in another column but same rows

From Dev

How to count number of rows in a table when table row is added dynamically

Related Related

  1. 1

    SQL - Delete row based on number of rows in another table

  2. 2

    Adding missing rows from the another table based on 2 columns

  3. 3

    Insert multiple rows in one table based on number in another table

  4. 4

    select data.table R rows based on row number and condition

  5. 5

    Sqlite - Update table rows based on another data in the row

  6. 6

    SQL Hide/Show rows based on row count from another table

  7. 7

    Excel adding rows based on if they are a number

  8. 8

    Adding multiple rows of a table to another table

  9. 9

    How to use PHP to query MySQL for certain rows, then for each row, based on a UID, query another table based on value?

  10. 10

    SQL - Need to update a value in a table based the number of relations its row has to another table

  11. 11

    Adding/Deleting table rows based on Select value

  12. 12

    adding multiple rows in mysql table based on an array

  13. 13

    Expanding query table rows based on another table

  14. 14

    Adding a Row Number to a Temp Table in Stored Procedure

  15. 15

    Compare two table and adding row based on condition

  16. 16

    JQuery Adding new Row in Table based on Selection

  17. 17

    Compare two table and adding row based on condition

  18. 18

    Adding empty number of rows in gridview based on grid rows count

  19. 19

    Select rows according row type in another table

  20. 20

    Select rows with show flag but based on another table

  21. 21

    MySQL - Query For Rows With Updates Based On Another Table

  22. 22

    Searching for number of values in one table, resizing number of rows in another table

  23. 23

    insert a row in 3 tables when adding another row for a new table

  24. 24

    Matlab adding rows to a table from another table with different dimensions

  25. 25

    R - fill rows of a column down based on another row in another column

  26. 26

    How to add certain number of rows based on values on the rows of another variable

  27. 27

    Adding rows from one IEnumerable to another based on conditions

  28. 28

    Adding multiple cells in a column based on a value in another column but same rows

  29. 29

    How to count number of rows in a table when table row is added dynamically

HotTag

Archive