?
Solved

Question on NON EXISTS/RETURN and GO

Posted on 2013-02-04
2
Medium Priority
?
288 Views
Last Modified: 2013-02-04
I have a block of script like this:

IF NON EXISTS (select 1 from client where clientid = 1)  <------- LINE1
RETURN;   <-------- LINE2

IF column 1 does not exists alter table ......
go

IF table_A not exists  create table_A
go

The problem is that after LINE2 is exec, it continue to EXEC the rest of the scripts. The intention is to exit the script if LINE1 returns true.
BTW, I cannot use EXIT, because it is called by other script, which will handle the exception differently.

Because the rest of script is so large, I do wish to keep the GO between the script lines.

Is there anyone can help me figure out what goes on here?

Thanks in advance.
0
Comment
Question by:chuang4630
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 2000 total points
ID: 38852038
The problem is that after LINE2 is exec, it continue to EXEC the rest of the scripts. The intention is to exit the script if LINE1 returns true.
...
Because the rest of script is so large, I do wish to keep the GO between the script lines.

If you cannot remove the GO, then there is not much you can do about it.
0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 2000 total points
ID: 38852059
From SQL Server's BOL (my emphasis):
SQL Server utilities interpret GO as a signal that they should send the current batch of Transact-SQL statements to an instance of SQL Server. The current batch of statements is composed of all statements entered since the last GO, or since the start of the ad hoc session or script if this is the first GO.
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question