title: Join two queries become one subquery
body: <p>I want to ask how to combine these two queries become one subquery?</p>
  
  <pre><code>select c.CustomerName, A.Qty
  from Customer c join (select s.CustomerID, pd.Date, s.Qty
       from Period pd join Sales s on pd.TimeID = s.TimeID) A on c.CustomerID = A.CustomerID
  where @Date = A.Date
  </code></pre>
  
  <p>and </p>
  
  <pre><code>select sum(case when (pd.Date between '2010-03-15' and @Date) then s.Qty else 0 end) as TotalQty
  from Period pd full join Sales s on pd.TimeID = s.TimeID full join Customer c on s.CustomerID = c.CustomerID
  group by c.CustomerName, c.CustomerID
  </code></pre>
  
  <p>They should result one table contains these following columns: CustomerName, Qty, and TotalQty. I've tried many ways but they didn't work at all. Really hope your help, thanks.</p>