Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. -- OrtizOL - xCSw - http://ortizol.blogspot.com
  2.  
  3. SELECT c.CustomerID,
  4.     SalesPersonPhone = spp.PhoneNumber,
  5.     CustomerPhone = pp.PhoneNumber,
  6.     PhoneNumber = COALESCE(pp.PhoneNumber, spp.PhoneNumber, 'SIN TELÉFONO')
  7. FROM Sales.Customer c
  8.     LEFT OUTER JOIN Sales.Store s
  9.         ON c.StoreID = s.BusinessEntityID
  10.     LEFT OUTER JOIN Person.PersonPhone spp
  11.         ON s.SalesPersonID = spp.BusinessEntityID
  12.     LEFT OUTER JOIN Person.PersonPhone pp
  13.         ON c.CustomerID = pp.BusinessEntityID
  14. ORDER BY CustomerID;