Solved

Question on NON EXISTS/RETURN and GO

Posted on 2013-02-04
2
230 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
  • 2
2 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 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 500 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help Required 3 96
Find SQL query used by application 3 19
TSQL query to generate xml 4 34
sqlserver get datetime field and create a string 5 18
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
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…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

773 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