DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
SITE SEARCH SQLUSA.com HEADLINES NEWS
SQL E/BOOKS   SQL 2014 PROGRAMMING   DOWNLOADS
SCRIPTS SQL 2005 SQL 2008 ARTICLES
SQL JOBS TWITTER FORMAT VIDEOS
How to tell the difference between empty and null strings?

Execute the following Microsoft SQL Server T-SQL scripts in SSMS Query Editor for demonstrating the differences between empty and null strings.

 

DECLARE @NullString varchar(32) = NULL

DECLARE @EmptyString varchar(32)= ''

 

-- EMPTY String

SELECT LEN(@EmptyString)

-- 0

SELECT DATALENGTH(@EmptyString)

-- 0

/********** TEST FOR EMPTY STRING *************/

SELECT 'Alpha' WHERE @EmptyString = ''

-- Alpha

SELECT 'Alpha' WHERE LEN(@EmptyString)=0

-- Alpha

 

/********** TEST FOR NOT NULL STRING *************/

SELECT 'Alpha' WHERE @EmptyString is not null

-- Alpha

 

-- NULL String

SELECT LEN(@NullString)

-- NULL

SELECT DATALENGTH(@NullString)

-- NULL

/********** TEST FOR EMPTY STRING *************/

SELECT 'Alpha' WHERE @NullString = ''

-- (0 row(s) affected)

SELECT 'Alpha' WHERE LEN(@NullString)=0

-- (0 row(s) affected)

 

/********** TEST FOR NOT NULL STRING *************/

SELECT 'Alpha' WHERE @NullString is null

-- Alpha

Exam Prep 70-461
Exam 70-461
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE