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.
Author |
Topic |
wondering_sa
Starting Member
8 Posts |
Posted - 2012-11-06 : 00:37:09
|
Hi Everybody We ship books - no more than 10 books per box. And Other items (toys, etc.) – no more than 15 pounds per box. Books are shipped separately from Other items. But orders usually contain a mix of items (let's say: 28 Books and 34 pounds of Other items).Is there a way to create a packing slip for every box In the case described above: - Two boxes with 10 books each - One box with 8 books - Two boxes with 15 pounds of Other items each - One box with 9 pounds of Other itemsThank you! |
|
karthik0805
Starting Member
14 Posts |
Posted - 2012-11-06 : 01:39:46
|
DECLARE @TABLE TABLE(ORDERID INT, BOOK INT, ITEM INT)INSERT INTO @TABLE SELECT 1,28,34UNION ALLSELECT 2,34,48SELECT * FROM @TABLESELECT ORDERID,ITEMS,BOX_CNT FROM (SELECT ORDERID,BOOK/10 'BOX_10_BOOKS',1 'BOX_EXTRA_BOOKS',ITEM/15'BOX_15_POUND_ITEM',1 'BOX_EXTRA_ITEM' FROM @TABLE)AUNPIVOT(BOX_CNT FOR ITEMS IN(BOX_10_BOOKS,BOX_EXTRA_BOOKS,BOX_15_POUND_ITEM,BOX_EXTRA_ITEM))AS A1 |
|
|
|
|
|
|
|