SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Crazy bug in SQL Server 2000
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Ben999
Starting Member

1 Posts

Posted - 11/21/2012 :  19:13:02  Show Profile  Reply with Quote
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

USA
15663 Posts

Posted - 11/22/2012 :  07:46:35  Show Profile  Visit robvolk's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000