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
 Item grouping for packing slips

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 items


Thank 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,34
UNION ALL
SELECT 2,34,48
SELECT * FROM @TABLE
SELECT 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)A
UNPIVOT(BOX_CNT FOR ITEMS IN(BOX_10_BOOKS,BOX_EXTRA_BOOKS,BOX_15_POUND_ITEM,BOX_EXTRA_ITEM))AS A1
Go to Top of Page
   

- Advertisement -