Use Northwind; GO select c.CustomerID, c.CompanyName, c.City, c.Country , [Orders] = STUFF(( select ', ' + CAST(o.OrderID as VARCHAR) + ' (' + convert(varchar, o.OrderDate, 101) + ')' from Orders o where o.CustomerID = c.CustomerID for XML PATH ('')), 1, 2, '') from Customers c left join Orders o on o.CustomerID = c.CustomerID group by c.CustomerID, c.CompanyName, c.City, c.Country order by c.CustomerID
Results:
CustomerID | CompanyName | Orders |
---|---|---|
ALFKI | Alfreds Futterkiste | 10643 (08/25/1997), 10692 (10/03/1997), 10702 (10/13/1997), 10835 (01/15/1998), 10952 (03/16/1998), 11011 (04/09/1998) |
ANATR | Ana Trujillo | 10308 (09/18/1996), 10625 (08/08/1997), 10759 (11/28/1997), 10926 (03/04/1998) |
ANTON | Antonio Moreno | 10365 (11/27/1996), 10507 (04/15/1997), 10535 (05/13/1997), 10573 (06/19/1997), 10677 (09/22/1997), 10682 (09/25/1997), 10856 (01/28/1998) |
No comments:
Post a Comment