17 January 2014

COALESCE Function In Sql Server



During  Development we have use more time Coalesce method If someone have home mobile number or mobile number suppose if you display available first record means you can use coalesce method or concatenate columns we use this coding
CREATE TABLE student 
( 
id int IDENTITY(1,1) NOT NULL, 
name varchar(50),  
mobile varchar(50) , 
homephoneno varchar(50)  
)
select * from student
OUTPUT

If use Coalesce function 

select name ,coalesce(mobile,homephoneno) 
PhoneNo from student 
OUTPUT


No comments:

Post a Comment