SQL Server 2000/2005 Compatibility Bug?

Had a bit of a frustarting day today with SQL Server 2005! I was upgrading a database from 2000 to 2005 but at the same time stripping out some unwanted procedures, so I was proceeding one at a time …
 
I found that I was getting an error message "Invalid Syntax near ‘E’".  I finally tracked this down to the following syntax not being liked by SQL 2005
 
… SQL Code …
 
IF @@ERROR = 0

RETURN (0)

–Error Handler

Error_Handler:

 
… Error Loggin SQL Code …
 
Yes! I know! You should use BEGIN TRY etc, etc in 2005, but these scripts I’m working on need to run in both 2000 and 2005.
 
This syntax was fine in 2000, but not in 2005.  So … the fix?  Well after 2 hours + scratching my head I found the following worked
 
 
… SQL Code …
 

IF

@@ERROR > 0 GOTO error_handler

RETURN (0)

error_handler

:

 
Don’t ask me why ….
 
 Dave Mc
 
Advertisements

About davemcmahon81
Software Developer & Architect, User Group Leader, Speaker, Writer, Blogger, Occasional Guitarist, Man-made Global Warming Sceptic, Climate Change Believer, General Optimist but most of all proud Husband and Dad ...

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: