You are here: Re: NULLS and '' « MsSQL Server « IT news, forums, messages
Re: NULLS and ''

Posted by Erland Sommarskog on 02/06/07 22:53

Paul (paulwragg2323@hotmail.com) writes:
> If I have a column DESCRIPTION VARCHAR(250) and the value is empty
> i.e. NULL then
> shouldn't doing a:
>
> SELECT TAB1.DESCRIPTION
> FROM TABLE1 TAB1
> WHERE TAB1.DESCRIPTION IS NOT NULL
> AND DATALENGTH(TAB1.DESCRIPTION) = 0
>
> always return zero records?
> A VARCHAR is variable length based on the actual data stored in it, so
> shouldn't a VARCHAR column of zero DATALENGTH be NULL?

No:

DECLARE @x varchar(234)
SELECT @x = ''
SELECT isnull = CASE WHEN @x IS NULL THEN 1 ELSE 0 END,
bytes = datalength(@x)

NULL and the empty string are two different values. Or maybe they the
same two values. After all, NULL is the unknown value, so you don't
know what it is. The empty string, on the other hamd, is a known value.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация