Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 a doubt

Author  Topic 

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-11-10 : 05:46:29
hi all,
my two queries below are

1
declare @chr varchar(130)
select @chr=@chr+[end] from show
select @chr
will give null as output

2
declare @chr varchar(130)
set @chr=''
select @chr=@chr+[end] from show
select @chr
will give expected result

whuy is this so?

thanx in advance

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-10 : 05:51:37
because in first case @chr is not initialised so it will take NULL value. and concatenation with NULL yields NULL
Go to Top of Page

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-11-10 : 06:01:27
ok,thanks visakh..
the wats the difference between NULL AND '' ????
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-10 : 06:07:37
NULL means unknown value. its not stored internally as a value. whereas '' means blank value. All operators like >,<,=.. will work with '' but not with NULL under default conditions.
The behaviour can however be changed by changing ANSI NULL settings.
Go to Top of Page

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-11-10 : 06:10:52
ok thanx
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-10 : 06:15:32
welcome
Go to Top of Page
   

- Advertisement -