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.
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.
Comments