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
Solved

Question on NON EXISTS/RETURN and GO

Posted on 2013-02-04
2
242 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql server query 12 26
query linked sql table field from access 4 22
question about results where i dont have a match 3 23
SQL Recursion schedule 13 16
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
I have a large data set and a SSIS package. How can I load this file in multi threading?
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.
Viewers will learn how the fundamental information of how to create a table.

829 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