I started working on this, and its taking me way longer then expected.The following query will currently tell you if the order can ship from one warehouse. I haven't gotten the calculation done for how many warehouses the minumum will be if it can't ship from one yet because I need to leave for somewhere. The main issue was dealing with the warehouse in the column format rather then row. Once I got it into rows it was going a lot easier. Hopfully this is a start I'll try to finish it later if I have time.create table #tmp(Productid varchar(50),whqty int,whID int)insert into #tmp(ProductID,whqty,whid)select s.ProductID,s.wh1onhand,1 from Stock s left join Cart c on s.ProductID = c.ProductIDwhere c.UserID = @UserIDunion allselect s.ProductID,s.wh2onhand,2 from Stock s left join Cart c on s.ProductID = c.ProductIDwhere c.UserID = @UserIDunion allselect s.ProductID,s.wh3onhand,3 from Stock s left join Cart c on s.ProductID = c.ProductIDwhere c.UserID = @UserIDunion allselect s.ProductID,s.wh4onhand,4 from Stock s left join Cart c on s.ProductID = c.ProductIDwhere c.UserID = @UserIDselect c.ProductID, c.Qty, t.whqTY, t.WHID, case when t.qty >= c.qty then 1 else 0 end as [Inwarehouse] --A ID letting me know that there is a warehouse --that has the entire qtyinto #tmpStagingfrom Cart c Inner JOIN #TMP ton t.ProductID = c.ProductIDgroup by tt.whidwhere c.UserID = @UserID--Any item that show up will meant the order can ship from 1 warehouse = 1 ship chargeselect a.WHIDfrom #TmpStaging awhere a.InWarehouse = 1group by a.whidhaving count(*) = (Select count(*) from cart c where c.UserID = @UserID))