Difference by SQL NULL and empty string ‘ ‘

What is the difference between null and  ” (empty string)?

Null is actually a value which means something is empty (confirmed empty not just left blank).

” mean a string that has not value in it.

ALTER PROCEDURE test_null
-- Add the parameters for the stored procedure here
@ID int = null,
@name varchar(25) = null
AS
BEGIN

print 'Actual value of Name: '
print @name;

if (@name = '')
print 'Name : empty string';
else
print 'Name : Not empty string';

if (@name is null) // note @name = null is incorrect syntax but will not show any error
print 'Name : null';
else
print 'Name : Not null';

END
GO

///////////////////////////////////////////////////////////////

exec test_null @id=12

exec test_null @name=null

Advertisements
Aside | This entry was posted in SQL Server 2008. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s