Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 20, 2015 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/0276d9404067c9fb69a6 to your computer and use it in GitHub Desktop.
Save Fhernd/0276d9404067c9fb69a6 to your computer and use it in GitHub Desktop.
Uso de la función COALESCE en T-SQL.
-- OrtizOL - xCSw - http://ortizol.blogspot.com
SELECT c.CustomerID,
SalesPersonPhone = spp.PhoneNumber,
CustomerPhone = pp.PhoneNumber,
PhoneNumber = COALESCE(pp.PhoneNumber, spp.PhoneNumber, 'SIN TELÉFONO')
FROM Sales.Customer c
LEFT OUTER JOIN Sales.Store s
ON c.StoreID = s.BusinessEntityID
LEFT OUTER JOIN Person.PersonPhone spp
ON s.SalesPersonID = spp.BusinessEntityID
LEFT OUTER JOIN Person.PersonPhone pp
ON c.CustomerID = pp.BusinessEntityID
ORDER BY CustomerID;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment