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 |
|
dmcbrier
Starting Member
5 Posts |
Posted - 2011-11-11 : 10:46:50
|
| I have a database with the following:SKU Qty Status Branch1 84 Do Not Reorder 11 359 Stock 21 138 Stock 31002 373 Stock 11003 0 Stock 11003 0 Stock 21003 18 Stock 31003 28 Stock 41012 0 Stock 1 1012 0 Stock 21012 0 Stock 31012 1 Do Not Reorder 41013 6 Stock 11014 0 Stock 11014 0 Stock 2Goal 1:I need to know the SKU's that are 'Do Not Reorder'SELECT SKU, QtyFROM Table NameWHERE (Status = N'Do Not Reorder')ORDER BY SKUGoal 2: Send the Stock from a Do Not Reorder Branch to the Stock BranchTherefore 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? HelpOutput Goal:SKU's that are both Do Not Reorder and StockSKU 1SKU 1012 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-11 : 10:50:12
|
| [code]SELECT SKUFROM tableGROUP BY SKUHAVING COUNT(CASE WHEN Status='Do Not Reorder' THEN 1 ELSE NULL END) > 0AND COUNT(CASE WHEN Status='Stock' THEN 1 ELSE NULL END) > 0[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
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. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-11 : 12:15:18
|
| wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|