Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

MS SQL

Posted Oct 3, 2000

Getting a Return Value From EXEC

By Alan Enderby

-- The procedure

drop proc exec_with_return_code
go
create proc exec_with_return_code @tsql varchar(255)
as
set nocount on
create table #return (code int null)
insert into #return EXEC ('DECLARE @rc int exec @rc=' + @tsql + '
select code=@rc')
declare @rc int select @rc=isnull(code,0) from #return
return @rc
go

-- A test procedure

drop proc return_me
go
create proc return_me @rc int=0
as
return @rc
go

--Test

declare @rc int
exec @rc=exec_with_return_code 'return_me 12'
select 'The return code is'=@rc



MS SQL Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
MS SQL Forum
Topic By Replies Updated
SQL 2005: SSIS: Error using SQL Server credentials poverty 3 August 17th, 07:43 AM
Need help changing table contents nkawtg 1 August 17th, 03:02 AM
SQL Server Memory confifuration bhosalenarayan 2 August 14th, 05:33 AM
SQL Server Primary Key and a Unique Key katty.jonh 2 July 25th, 10:36 AM