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)
 Try Catch

Author  Topic 

doran_doran
Posting Yak Master

179 Posts

Posted - 2009-12-10 : 10:57:18
I have declared some variables on the top then I have try catch. Then after the catch I have an insert statement to log into a logTable.

Why the variable I declared before the begin try is not accessible after the end catch?

X002548
Not Just a Number

15586 Posts

Posted - 2009-12-10 : 11:07:28
Want to post a sample?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-12-10 : 13:33:55
what are you doing inside catch? is there a transaction which is rolledback inside catch?
Go to Top of Page

doran_doran
Posting Yak Master

179 Posts

Posted - 2009-12-10 : 13:49:28
alter procedure [dbo].[usp_sendmail]
(
@user varchar(100),
@runDate datetime,
@body varchar(500)
set @user=system_user
set @runDate = getdate()
set @body = @user + @runDate + 'record has been updated.'
begin try
update statment
end try
begin catch

end catch

-- now keep a log of send email
another insert statement with variables declared above



)
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-12-10 : 14:51:56
quote:
Originally posted by doran_doran

alter procedure [dbo].[usp_sendmail]
(
@user varchar(100),
@runDate datetime,
@body varchar(500)
set @user=system_user
set @runDate = getdate()
set @body = @user + @runDate + 'record has been updated.'
begin try
update statment
end try
begin catch

end catch

-- now keep a log of send email
another insert statement with variables declared above



)




you're going to error out on the line in red above. need to cast the datetime to a varchar
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-10 : 15:14:27
doran, please post the full code.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-12-10 : 17:15:55
Need to check for an -811

http://www.dbforums.com/microsoft-sql-server/1651355-multiple-rows-sql-server-2008-a.html



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -