Home >> FAQs/Tutorials >> SQL Server FAQ

SQL Server FAQ - Assigning NULL Values to Variables or Columns

By: FYIcenter.com

(Continued from previous topic...)

How To Assign NULL Values to Variables or Columns?

The rule for assigning NULL values to variables or table columns is simple: Use keyword "NULL" directly as normal values. Specificly,

  • "NULL" can be used in SET statements to assign NULL values to variables.
  • "NULL" can be used in SET clauses in UPDATE statements.
  • "NULL" can be used in value lists in INSERT statements.
  • "NULL" can be used in parameter lists when calling stored procedures or functions.

The tutorial script below gives you some good examples:

USE FyiCenterData;
GO

-- assign NULL values to variables
DECLARE @birth_date DATETIME;
SET @birth_date = NULL;
SELECT @birth_date;
GO
-----------------------
NULL

-- assign NULL values to columns
UPDATE fyi_links SET notes = NULL;
GO
(8 row(s) affected)

-- assign NULL values to parameters
EXEC sp_help NULL;
GO
Name            
----------------
fyi_links_dump  
fyi_links_top   
fyi_links_view  
...

(Continued on next topic...)

  1. What Are NULL Values?
  2. How To Assign NULL Values to Variables or Columns?
  3. What Happens If NULL Values Are Involved in Arithmetic Operations?
  4. What Happens If NULL Values Are Involved in String Operations?
  5. What Happens If NULL Values Are Involved in Datetime Operations?
  6. What Happens If NULL Values Are Involved in Bitwise Operations?
  7. What Happens If NULL Values Are Involved in Comparison Operations?
  8. What Happens If NULL Values Are Involved in Boolean Operations?
  9. How To Test NULL Values Properly?
  10. How To Replace NULL Values in Expressions using ISNULL()?
  11. How To Replace Given Values with NULL using NULLIF()?

Related Articles:

More...


Other Tutorials/FAQs:

More...


Related Resources:

More...


Selected Jobs:

More...