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)
 int value = null

Author  Topic 

toad32
Starting Member

2 Posts

Posted - 2009-11-04 : 09:34:39
I have the following code that has been working for the last year.

declare @id as int
set @id=0

select @id=max(version_id) from order_Details
where prod_id = '666'

if @id=0 or @id = null
set @id=1
else
set @id=@id+1

the result of the max query returns no records and hence the @id value will become null but when i use the if statement it always falls in to the else part and adding 1 to a null value results in null. This @id variable is used to insert a record into a table that does not except nulls. hence the problem.

I know by chaning the "= null" to "is null" solves the problem but the code has not been changed and it has been working for the last year.

is there a serevr setting that could effect the way null or max is handled as we have a third part that can control the serever settings and we are not sure if they have changed something.

thanks in advance.

toad32
Starting Member

2 Posts

Posted - 2009-11-04 : 10:16:28
thank you but i have found the setting. running the following put it back to what it orginally was.

SET ANSI_NULLS OFF
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-04 : 10:22:06
Thank you for coming back and posting your solution.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -