Search
 
SCRIPT & CODE EXAMPLE
 

SQL

coalesce sql

Return the first non-null value in a list:

SELECT COALESCE(NULL, NULL, NULL, 'W3Schools.com', NULL, 'Example.com');

-- output: W3Schools.com
Comment

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
*/
Comment

MSSQL COALESCE

SELECT COALESCE(NULL, NULL, NULL, 'HELLO WORLD', NULL, 'Example.com');

RESULT
'Hello World' --> First value not null
Comment

PREVIOUS NEXT
Code Example
Sql :: order of execution in sql 
Sql :: sql order 
Sql :: oracle for loop on list 
Sql :: dns slave zone convert 
Sql :: sql field equals multiple values 
Sql :: tsql from yyyymm to date 
Sql :: Question 7: Write an SQL query to print details of the Workers who have joined in Feb’2014. 
Sql :: sql not in operator 
Sql :: xml to column sql 
Sql :: create user with encrypted password postgresql 
Sql :: sql primary key 
Sql :: SQL Syntax of FULL OUTER JOIN 
Sql :: psql initialization 
Sql :: sql join on wildcard 
Sql :: add column first position mysql 
Sql :: flask sqlalchemy remove duplicates 
Sql :: between keyword sql 
Sql :: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails 
Sql :: mysql set column equal to another automatic 
Sql :: insert data to postgresql from excel 
Sql :: show last sql executed in oracle 
Sql :: Remove duplicate old value in mysql 
Sql :: mysql large import 
Sql :: column must appear in the GROUP BY clause or be used in an aggregate function 
Sql :: trigger sql server 
Sql :: how to add multiple column in mysql 
Sql :: mysql error 1452 
Sql :: execution time of mysql query 
Sql :: SQL Greater Than Operator 
Sql :: left join 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =