SQL Server - ISNULL
ISNULL checks that value is null then return given expression.
Let's understand the practical example, if we have NULL> then we have to show any default value then we use the ISNULL.
Below is the syntax of ISNULL.
Syntax for ISNULL
Below example where we create one string variable and not assign any value to it (so default value is null), if value is null then we need default value 'WebNetGuru' as output.
Note : If we observe the above example we can find out that ISNULL check if first parameter having NULL value then it will show the value of second parameter or else it will first parameter value.
Below example where we create one string variable and assign some value to it.
Lets find out the practical example of ISNULL.
We have student table and it contain student name, roll number and city, but unfortunately some student not having city. Consider the below result set.
Now we required output that if student city is not available then show the 'Mumbai' as default city using ISNILL.