Quantcast
Channel: SQL Server
Viewing all articles
Browse latest Browse all 3819

Blog Post: T-SQL COALESCE Example

$
0
0
T-SQL COALESCE SQL Server T-SQL coalesce simplifies the use of a case statement to find the first non-null value of your expression.  For example, I want to return the products in the AdventureWorks sample database and show the SellEndDate if it exists or the SellStartDate if the SellEndDate is null. Example Script: SELECT [ProductID] ,[Name] ,[SellStartDate] ,[SellEndDate] ,coalesce([SellEndDate],[SellStartDate]) as Sell_Date_End FROM [AdventureWorks2014].[Production].[Product] where ProductID 720 Results: As you can see in the above image, row 5 populates the Sell_Date_End column with 5/29/2013 since the SellEndDate is not null.  Otherwise, if the SellEndDate is null the SellStartDate is populated.   For complete information on Coalesce see MSDN The post T-SQL COALESCE Example appeared first on Derek E Wilson - Blog .

Viewing all articles
Browse latest Browse all 3819

Latest Images

Trending Articles



Latest Images