Definition:
In SQL Server ISNULL() function is used to replace null value with other value. Basically ISNULL allows a display of the particular value as substitution for NULL.
Syntax:
ISNULL(Expression , replace_Value )
If Expression is null then replace_Value will be returned, otherwise Expression will be returned
Example:
SELECT ISNULL(1, 10) – Output is 1
SELECT ISNULL(NULL, 10) – Output is 10
Script: CREATE TABLE Student ( sub VARCHAR(10), marks INT ) --Insert stattements INSERT INTO Student VALUES('Maths',67) INSERT INTO Student VALUES('English',NULL) SELECT sub,isnull(marks,0) AS Marks FROM student |
Output: Table data:After applying ISNULL: For English the student marks are null so it returned 0. For Maths subject student marks is not null so orginal value is returned. |
insert into Student values('English','s') --Error :Conversion failed when converting the varchar value 's' to data type int Because marks in int and replacement value is varchar. |
1 Comments:
Post a Comment