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
 SQL Query Help

Author  Topic 

dmcbrier
Starting Member

5 Posts

Posted - 2011-11-11 : 10:46:50
I have a database with the following:

SKU Qty Status Branch
1 84 Do Not Reorder 1
1 359 Stock 2
1 138 Stock 3
1002 373 Stock 1
1003 0 Stock 1
1003 0 Stock 2
1003 18 Stock 3
1003 28 Stock 4
1012 0 Stock 1
1012 0 Stock 2
1012 0 Stock 3
1012 1 Do Not Reorder 4
1013 6 Stock 1
1014 0 Stock 1
1014 0 Stock 2

Goal 1:
I need to know the SKU's that are 'Do Not Reorder'
SELECT SKU, Qty
FROM Table Name
WHERE (Status = N'Do Not Reorder')
ORDER BY SKU

Goal 2: Send the Stock from a Do Not Reorder Branch to the Stock Branch
Therefore I need to know the SKU numbers tHat are stock in one branch, but Do Not Reorder in another branch.

Not sure how to achieve Goal 2? Help

Output Goal:
SKU's that are both Do Not Reorder and Stock
SKU 1
SKU 1012


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-11 : 10:50:12
[code]
SELECT SKU
FROM table
GROUP BY SKU
HAVING COUNT(CASE WHEN Status='Do Not Reorder' THEN 1 ELSE NULL END) > 0
AND COUNT(CASE WHEN Status='Stock' THEN 1 ELSE NULL END) > 0
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dmcbrier
Starting Member

5 Posts

Posted - 2011-11-11 : 12:07:06
Thank you very much. This worked great!!!!
Much Appreciated!!!!!!!!!!!!!!!!!!!!!

I was hitting my head against the desk.


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-11 : 12:15:18
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -