Monday, August 13, 2012

ISNULL(expressions)


In SQL 2008 r2, we have ISNULL() T-SQL predefined function to validate null values. If the retruning value is null then we can replace the variable with our predefined value.

Syntax: ISNULL(check_expression , replacement_value )

Eg:

DECLARE@IsPhoneNumber INT
SELECT @IsPhoneNumber = ISNULL(PhoneNumber,0) FROM dbo.tblAddress WHERE CustomerID= 1001
SELECT@IsPhoneNumber


The Result will be:
  • Prints '0' if the PhoneNumber value is NULL for given customer ID.
  • Prints 'PhoneNumber' if the given customerID holds phone number in that row.

No comments:

Post a Comment