Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 [Resolved] Use of "Begin...End"

Author  Topic 

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-03-03 : 08:31:31
I am not very familiar with the "Begin...End" scope and would like to post a couple of lines for comments by the experts.

begin transaction
exec('insert into ZyTax.dbo.ttable(
report_state, report_year....
Select ztadds, ztyear ...
from AS400SRV_MSDASQL.VGSYS400.' + @AliasLibrary + '.' + @SourceFile)
COMMIT TRANSACTION
if @@error <> 0
begin
set @RetValue = 'Error: upload to ZyTax failed'
set @InsertOK = 0 -- false
end



if @InsertOK = 1
if @UpdateOK = 1
if @SourceMember = 'CO55PC'
exec('Update VGITFRLIB.F551202 a set rczflg = 2 where exists (select 1 from ' + @AliasLibrary + '.' + @SourceFile + ' b
where a.vcfyr = b.ztyear and
a.vcpn = b.zt#mt and
a.rcdoca = b.zt#ds2 and
a.vcpex1 = b.ztprd1 and
b.ztscht = "DISB")') at AS400SRV_MSDASQL
if @@error <> 0
begin
set @RetValue = 'Update processing flag failed for member ' + @SourceMember + ' transaction type DISB'
set @UpdateOK = 0 -- false
end


Also my question is, if there are no records to be updated, will that cause @@error to have a value?

Thank you.




sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-03-03 : 08:44:53
No, @@error won't have a value then.
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-03-03 : 08:45:27
You can make use of @@rowcount, incase you need a check basis number or rows inserted/updated.
Go to Top of Page
   

- Advertisement -