How to fetch a result of an int column data type from a table and if no record found select 0 as default in microsoft sql azure
I had tried ISNULL but it does not work.
In case there is a table named student.
Column_Name data_type
roll_nbr int
name varchar(30)
Select ISNULL(roll_nbr,0) FROM student where name = ‘Sam;
I am expecting the query to return roll_nbr from the table if exists else return 0 as default if no rows is found.
2
Answers
You can modify your Azure Sql Query as below
Using COALESCE()
(http://sqlfiddle.com/#!18/9a6eaf/2)
The subquery will return the RollNumber if satisfies the
where
condition else it will return blank/null result. Use ofCOALESCE
function on subquery will return first not null value.Using ISNULL()
http://sqlfiddle.com/#!18/9a6eaf/6