To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here

HOME News MS SQL Oracle DB2 Access MySQL PHP Scripts Books Links DBA Talk


Go Back   Database Journal Forums > Database Discussions > MS SQL Server 7/MS SQL Server 2000

MS SQL Server 7/MS SQL Server 2000 Discuss Microsoft SQL Server 2000 and earlier in this forum

Reply Post New Thread
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 04-21-2006, 07:07 AM
cmorel cmorel is offline
Registered User
 
Join Date: Apr 2006
Location: Paris
Posts: 7
Syntax error stops the execution of script!!!

Hello everybody!
There is something I still not understand in the way the DB engine works.

I have the following query, which purposefully contains an error:
Code:
declare @mystr nvarchar(3); set @mystr = 'C01'; declare @myint int; set @myint = @mystr;
Obviously, you cannot assign the string 'C01' to variable of type int! This is a syntax error:

Server: Msg 245, Level 16, State 1, Line 1
Syntax error converting the nvarchar value 'C01' to a column of data type int.


If I embed that query in a string variable and call the sp_executesql procedure to process it or just use the EXEC statement, the error will be raised but the execution of query will stop neat, so that I won't be able to test the result of the call.

Here is my script:

Code:
	declare @myquery nvarchar(4000);
	set @myquery = 'declare @mystr nvarchar(3); set @mystr = ''C01''; declare @myint int; set @myint = @mystr;';
	exec sp_executesql @myquery;
	if @@ERROR <> 0
	begin
		print 'failed.'
	end
	else
	begin
		print 'done';
	end
For instance, if you run this script in query analyzer, no message gets printed at all in query analyzer

This seems to happen only with syntax errors.

How can I avoid this situation????

Thanks a lot.
Reply With Quote
Reply Post New Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 08:29 AM.


DatabaseJournal Recent Articles


 » Configuring Oracle as a Data Source for SQ...

 » Tips for Simplifying Crosstab Query Statem...

 » Redmond exploits MySQL uncertainty

 » Oracle Launches Oracle Global Trade Manage...

 » SQL Server 2008 RTM Support Ends April 13,...

Search Database Journal:
 








Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.