Nagaram (4/2/2013)
I edited the main post .Sean Lange let me know till if it not clear .. My english is not so good
Here is the logic:
select '11003291001-----NOB30000','0V003','A00A00',269,285,305,1 union all
select '11003291001-----NOB30000','03003','A00A00',287,30,305,2
output:
Invtid Siteid WhselocDaysQty
11003291001-----NOB30000 0V003A00A00269285
11003291001-----NOB30000 03003 A00A0026920 -- 305-285=20 (20 out of 30)
11003291001-----NOB30000 03003 A00A0028710 -- 10 out of 30
output record 1) priority row 1
output record 2) as per priority row 1 we can store more 20 Qty (from row-1, 305-285=20) , so in input row-2 , we can place 20 out of 30 for row1 days
output record 3 ) in input record 2 , from qty 30 we placed 20 in row2 so final output row can have 10 Qty
No worries about the English. You seem to do fine. Besides t-sql is the language of choice around here. 🙂
I am a little confused by where the logic comes from. I don't quite get what you are trying to do. I don't get why you have 3 rows now instead of 2. I think you want a select statement to split these by some logic but I can't follow it. Maybe you are trying to allocate 305 units ordered by priority? That is still only 2 rows no matter how I slice it. 285 for the first and the remaining 20 for the second. Help me understand.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/