SQL Server BasicsWhat is SQL Server database?What is RDBMS?What is Normalization?Why we use Denormalization?What_is_SQL?What is PL/SQL?Difference between SQL and PL/SQLDatabase TableOne to One RelationshipOne to Many RelationshipMany to Many RelationshipMany to One RelationshipString Data TypesNumber Data TypesDate Data TypesOther Data TypesCreate DatabaseDrop DatabaseCreating and Managing Users in SQL ServerCreate TableAlter TableDrop TableConstraints in SQL serverPrimary KeyForeign KeyUnique KeyCandidate KeyComposite KeyDifference between primary key and candidate keyPrimary key and foreign key relationshipSurrogate KeyCascading Referential Integrity ConstraintsSelf Referential Integrity ConstraintsInsert into statementInsert multiple recordsUpdate statementDelete statementTruncate statementDifference between Delete and TruncateAlias in SQL ServerSelect statementSelect DistinctSelect TopSelect IntoNull Functions(ISNULL(),NULLIF(),COALESCE())Sub QueryIdentity ColumnSequence objectDifference between sequence and identity columnSQL Server ClausesWHERE ClauseOrder By ClauseTop N ClauseGroup By ClauseHaving ClauseDifference between Where and HavingSQL Server OperatorsArithmetic OperatorsComparison OperatorsLogical OperatorsBitwise OperatorsAny OperatorsAll OperatorsUnion OperatorsUnion All OperatorsDifference between Union and Union AllIntersect OperatorExcept OperatorDifference between Except and IntersectJoinsInner JoinLeft JoinRight JoinFull JoinSelf JoinCross JoinViewsWhat are views?Create views using SSMSIndexed ViewsComplex ViewsCheck Option in ViewCheck Encryption in ViewSchema Binding Option in ViewRead-only ViewsUpdatable ViewsAdvantages and disadvantages of viewsCreate multiple views on one tableCan we implement index on views?Can we Perform Insert, update, delete operation on views?Stored Procedure and FunctionsWhat are Stored Procedures?Why we use stored procedures?Passing parameters to Stored procedureUser-Defined FunctionsDifference between UDF and Stored procedurePre-Defined Functions@@Indentity and Scope_IndentityNULLIF, ISNULL and COALESCE

Null Functions in SQL Server

In SQL Server, there are several functions available to handle NULL values. These functions allow you to perform operations on columns or expressions that may contain NULL values and handle them appropriately. Here are some commonly used NULL functions in SQL Server:

1- ISNULL(): The ISNULL() function replaces a NULL value with a specified value. It takes two arguments: the expression to be evaluated and the value to be returned if the expression is NULL.


SELECT ISNULL(column_name, replacement_value) AS new_column_name
FROM table_name;

2- COALESCE(): The COALESCE() function returns the first non-NULL expression from a list of expressions. It takes multiple arguments and evaluates them in order until a non-NULL value is found.


SELECT COALESCE(column_name1, column_name2, column_name3) AS new_column_name
FROM table_name;

3- NULLIF(): The NULLIF() function compares two expressions and returns NULL if they are equal; otherwise, it returns the first expression. It is often used to handle division by zero or when you want to replace a specific value with NULL.


SELECT NULLIF(expression1, expression2) AS new_column_name
FROM table_name;

4- ISNULL() vs COALESCE(): The ISNULL() function works with only two arguments and returns the replacement value if the expression is NULL. In contrast, the COALESCE() function can handle multiple arguments and returns the first non-NULL value from the list of expressions.

5- CASE statement: The CASE statement allows you to perform conditional logic and handle NULL values. You can use it to define different actions or values based on the presence or absence of NULL values.


SELECT column_name,
    CASE
        WHEN column_name IS NULL THEN 'Null value'
        ELSE 'Non-null value'
    END AS new_column_name
FROM table_name;

These NULL functions in SQL Server provide flexibility in handling NULL values during data retrieval and manipulation. They help you to replace, compare, or handle NULL values appropriately based on your specific requirements.