March 31, 2006 at 2:04 pm
I have a query where I am building a dynamic sql string and running it using sp_execute_sql. if that query fails, I still want to continue execution. I have an error checker, but it never makes it there, as soon as the error occurs, the procedure halts execution and reports the error. Any help would be much appreciated
March 31, 2006 at 9:34 pm
Will you please able to paste the query or part of the query ?
April 3, 2006 at 7:00 am
Sure, this is where it errors out, and i'd like to be able to catch the error, but when it errors, it doesn't even make it to the error handler
SET @sql = '
insert into nation_project.dbo.db_size(svr_name,db_name,db_size,stat_time) SELECT ''' + @srvName + ''' AS SVR_Name,
''' + @dbname +''' AS DB_Name ,
cast(sum(cast(size as decimal(10,2)) * 8 / 1024) as decimal(10,2)) AS DBSize, ''' + cast(@date as varchar(50)) + ''' Stat_Time FROM [' + @srvName + '].[' + @dbname + '].dbo.sysfiles'
EXECUTE(@sql)
SELECT @error = @@error
IF @error <> 0
BEGIN
SET @output_message = 'Error ' + cast(@error as VARCHAR(50)) + ' occured on statement'
--PRINT @sql
END
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply