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)
 ISNULL question

Author  Topic 

sujosh
Yak Posting Veteran

55 Posts

Posted - 2001-11-29 : 16:42:33
SELECT @trans_seq_num = max(trans_seq_num) FROM pv_trans
The @trans_seq_num will be null the first time and I want to set it to 1

So I thought I can do something like this and I got "Incorrect syntax near the keyword 'else'."

if isnull(@trans_seq_num,1)

else
@trans_seq_num = @trans_seq_num + 1

Any help is appreciated!
Thanks

izaltsman
A custom title

1139 Posts

Posted - 2001-11-29 : 16:49:36
I don't think you need an if/else construct at all... This will do just fine:

set @trans_seq_num = isnull(@trans_seq_num, 0)+1





Go to Top of Page

sujosh
Yak Posting Veteran

55 Posts

Posted - 2001-11-29 : 16:52:10
Thanks a lot!! appreciate it

Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2001-11-29 : 17:08:45
The isnull function doesn't return a yes/no even though it sounds like it should.
If the first argument is not null it returns that otherwise it returns the second.
Similar to a coalesce with a list of 2.

==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -