Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RETURN Doesn't Stop Script

Status
Not open for further replies.

grnzbra

Programmer
Mar 12, 2002
1,273
US
The following is at the beginning of a T-SQL script that calls, in succession, four stored procedures. If someone enters an invalid value, the script should not keep running. According to Microsoft Help, nothing after the RETURN should be executed. This keeps going. Is it possible that the problem is because nothing is calling this script; it is being executed directly from the query window? Is there another command that will stop the script

Code:
DECLARE @Version		CHAR(7)
DECLARE @VersionNum		INT
SET @Version = 'ENTER_CHECKLIST_VERSION_HERE'

PRINT @Version
SELECT @versionnum = 
	CASE ISNULL(@version,'')
		WHEN '' THEN 0
		WHEN 'ENTER_C' THEN 0
		WHEN '1.01.00' THEN 1
		ELSE 0
	END
PRINT @VersionNum
IF @versionnum = 0
BEGIN
	PRINT 'PLEASE ENTER A VALID PM CHECKLIST TEMPLATE VERSION.' 
	PRINT 'SEE "MAIN" WORKSHEET OF TEMPLATE FOR VERSION'
	PRINT 'Version: ' + @version
	RETURN
END
 
In your example, return is stopping the script.

I added another PRINT at the end, and that print didn't get printed. Therefore, I think whatever problem you're having, it must be something else.

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
There are a bunch of GO statements in the code after this snippet. Could that be the problem?
 
yes

Anything after the go would be considered a separate batch. Think of it this way... If you had multiple query windows with code in them. And you executed them, you wouldn't expect a return to stop the execution from the next tab would you?

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top