On Apr 22, 7:39 am, "Michael Tissington"
[quoted text, click to view] <mtissing...@newsgroup.nospam> wrote:
> I have a large SQL script file with lots of batch blocks (ending in GO).
>
> The first statement determine if the rest of the script should run using an
> IF NOT EXIST
>
> How do I skip to the end of the script file (or abort the script file) ?
This may be one of the ways . Others may post better ways .
Trick is create a dummy table with a column not null . When you want
to abort the job insert null value to dummy table
with set xact_abort on
Example
set xact_abort on
begin tran
create table #a (keyid1 int, keyid2 int )
insert into #a values (1,2)
select * from #a
create table #dummy (keyid int not null)
go
if not exists (select 1 from #a where keyid1 = keyid2 )
begin
print 'keyd1<>keyid2'
insert into #dummy values(null)
end
select keyid1 from #a
select keyid2 from #a
go
select keyid1 from #a
go
if @@trancount > 0
commit