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
 SQL Server Development (2000)
 Crazy bug in SQL Server 2000

Author  Topic 

Ben999
Starting Member

1 Post

Posted - 2012-11-21 : 19:13:02
I had a weird issue in an SQL Server 2000 stored procedure. I distilled the critical part of the procedure down to:


declare @X int

set @X = 1

-- Comment
if @X = 2

print cast(@X as varchar(10)) + ' = 2'

print 'Done'


The output is:
1 = 2
Done

Naturally it is disconcerting to find that 1 is equal to 2 and if-statements don't work! There are a few things that I've noticed will fix it, but none of them are ideal:
i. Deleting the comment
ii. Changing the comment from using '--' to using /* ... */
iii. Deleting the blank row after the if-statement
iv. Upgrading to a newer version of SQL Server (or a different RDBMS altogether)

Fortunately option iv. above is only a couple of weeks away, but if anyone knows of a patch or something for this problem, please let me know.

Thanks.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-11-22 : 07:46:35
Did you try enclosing that in BEGIN...END:
if @X = 2
BEGIN
print cast(@X as varchar(10)) + ' = 2'
END
This is a standard good practice. If there's some kind of parser error that leads to a downstream processing error this may correct it (since similar tweaks you've made also correct it).

SQL 2000 is end-of-life, if you've patched your server to Service Pack 4 and still have the error, then you'll need to upgrade, or just rewrite your code. If the bug still exists in SQL Server 2008/2012 then you should file a bug report on Microsoft Connect.
Go to Top of Page
   

- Advertisement -