Kristie
asked on
How to split a single row into multiple rows based upon a number value
I have a quick question. I am trying to split a single row into multiple rows based upon a specific number value. I want the single row to be split every time it has 50 units. So if a row has 150 units in it, the row will be split 3 times, with 50 units as the value for each. Or if the row has 233 units, the row will be split 5 times, 4 rows with 50 units and one row with 33 units.
Example:
Start:
Carrier Units
CBA Carriers 150 units
ABC Carriers 233 units
End:
CBA Carriers 50 units
CBA Carriers 50 units
CBA Carriers 50 units
ABC Carriers 50 units
ABC Carriers 50 units
ABC Carriers 50 units
ABC Carriers 50 units
ABC Carriers 33 units
Example:
Start:
Carrier Units
CBA Carriers 150 units
ABC Carriers 233 units
End:
CBA Carriers 50 units
CBA Carriers 50 units
CBA Carriers 50 units
ABC Carriers 50 units
ABC Carriers 50 units
ABC Carriers 50 units
ABC Carriers 50 units
ABC Carriers 33 units
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
the above is not what I am looking for. Please review my questions and table example.
Please post your table schema and a SQL Script to populate the data.
ASKER
ewangoya query works but takes a very long time to loop through all the records.
Try attached SQL sql1.sql
>> but takes a very long time to loop through all the records.<<
If you are still using SQL Server 2000, you may not have much choice.
If you are still using SQL Server 2000, you may not have much choice.
Open in new window
(source: http://www.select-sql.com/mssql/how-to-make-limit-from-to-in-mssql-2005.html)