Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 One column value to multiple rows

Author  Topic 

usenthil75
Starting Member

4 Posts

Posted - 2008-05-20 : 01:58:35
i want to split the value of one column into multiple rows. based on comp capacity. pl help me in writing query

Actual table
Product Id ProductQty CompCapacity
1 8000 5000
2 10000 5000
4000
4000

Resultant table
Product Id ProductQty CompCapacity
2 5000 5000
2 5000 5000
1 4000 4000
1 4000 4000

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-20 : 02:06:40
Your sample data is not clear. WHy 4000 does not have a ProductId? Also why have you split 800 into two 4000 while value for CompCapacity is 5000? Please specify your business rules.
Go to Top of Page

usenthil75
Starting Member

4 Posts

Posted - 2008-05-20 : 05:44:58
Product Qty is order qty. Truck Available with different capacities. I have to match order qty to Truck capacity. You can take truck no as reference on which the record set to be updated
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-20 : 05:48:24
quote:
Originally posted by usenthil75

Product Qty is order qty. Truck Available with different capacities. I have to match order qty to Truck capacity. You can take truck no as reference on which the record set to be updated


Truck no?I cant see such a field in your sample data. Can post your fll table structure plzz?
Go to Top of Page

usenthil75
Starting Member

4 Posts

Posted - 2008-05-20 : 05:53:50
Actual table
Truck No Product Id ProductQty CompCapacity
KA01A555 1 8000 5000
KA01A555 2 10000 5000
KA01A555 4000
KA01A555 4000

Resultant table
Truck No Product Id ProductQty CompCapacity
KA01A555 2 5000 5000
KA01A555 2 5000 5000
KA01A555 1 4000 4000
KA01A555 1 4000 4000
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-20 : 05:56:45
quote:
Originally posted by usenthil75

Actual table
Truck No Product Id ProductQty CompCapacity
KA01A555 1 8000 5000
KA01A555 2 10000 5000
KA01A555 4000
KA01A555 4000

Resultant table
Truck No Product Id ProductQty CompCapacity
KA01A555 2 5000 5000
KA01A555 2 5000 5000
KA01A555 1 4000 4000
KA01A555 1 4000 4000



How do you decide that 4000 actually corresponds to record with ProductId 1?
Go to Top of Page

usenthil75
Starting Member

4 Posts

Posted - 2008-05-20 : 06:11:16
select compartment sum of compcapacity = productqty and then split the product qty and assign against compcapacity
Go to Top of Page
   

- Advertisement -