Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

coalesce function in sql server

/* Return The First Non Null Value*/

SELECT Column_Name, COALESCE (Col1, Col2, Col3,...) AS Alias_Name FROM Table_Name

For Example
/*
ID First_Name Middle _Name Last_Name
1    Sam         null         null
2    null       John          null
3    null       null          smith
*/
SELECT ID,  COALESCE (First_Name, Middle_Name, Last_Name) AS Name 
FROM tblCOSTOMER
/*
Output
ID Name
1  Sam
2  John
3  smith
*/
 
PREVIOUS NEXT
Tagged: #coalesce #function #sql #server
ADD COMMENT
Topic
Name
7+7 =