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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 empty string assigned to int

Author  Topic 

zekekez
Starting Member

1 Post

Posted - 2004-08-26 : 18:35:55
if an empty string, '', is assigned to a variable of type int, comparison of the variable to '' or 0 is true.

query:
declare @x int
set @x = ''
if @x = '' print 'empty'
if @x = 0 print 0

result:
empty
0

I haven't come across this before. Is this normal?

Zeke

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-08-26 : 18:40:30
declare @x int
set @x = ''
print @x

Assigning @x to '' is actually setting it to 0. See above code. If you don't want it to be set to anything, set it to NULL.

Tara
Go to Top of Page
   

- Advertisement -