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
 How to select all lines with a spec value?

Author  Topic 

Peter2138
Starting Member

2 Posts

Posted - 2012-08-14 : 04:10:02
Hi All,

I have orders with orderlines, those orderlines have a status and a warehouse. The warehouse SEC is our mainwarehouse, and orderline status 30 is "completed"

How do I select complete orders? So, orders where all orderstatus with warehouse SEC are 30? (there may be other warehouses in an order but that's not an issue)

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-08-14 : 04:27:08
SELECT OrderNumber FROM dbo.OrderLines GROUP BY OrderNumber HAVING MIN(CASE WHEN Warehouse = '30' THEN 1 ELSE 0 END) = 1



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-08-14 : 04:27:49
SELECT OrderNumber FROM dbo.OrderLines GROUP BY OrderNumber HAVING MIN(CASE WHEN Status = '30' THEN 1 ELSE 0 END) = 1


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-14 : 10:34:07
it should be
SELECT OrderNumber FROM dbo.OrderLines GROUP BY OrderNumber HAVING MAX(CASE WHEN Warehouse='SEC' AND Status !='30' THEN 1 ELSE 0 END) =0



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

Go to Top of Page
   

- Advertisement -