Tuesday, September 6, 2011

ISNULL in sql server

In sql server ISNULL is used to replace one value with some other value. while executing some queries having aggregate functions it may not return the expected result set if table contains NULL values.
For Suppose EMPLOYEE table have the data:


SELECT COUNT(Name) FROM EMPLOYEE
SELECT SUM(Salary) FROM EMPLOYEE

SELECT COUNT(ISNULL(Name,1)) FROM EMPLOYEE
SELECT SUM(ISNULL(Salary,10000)) FROM EMPLOYEE

Above 4 queries will return 3,60000,4,70000 respectively.

No comments:

Post a Comment