Developing Matt

My Technical Journal

Calling a stored proc (within a stored proc)

with 2 comments

When a programmer migrates into t-sql logic they start asking questions like ‘how do you call a stored procedure from another stored procedure and use the resultset?’  So one way is to specify an output parameter.

create procedure dummyReturnLastName
@FullName varchar
(15),
@LastName varchar(15) output
as
begin
set
@lastname = substring(@fullname, charindex(‘ ‘,@fullname), len(@fullname)-charindex(‘ ‘,@fullname)+1)
end

And you call it with

declare @lastname varchar(15)
exec
dummyReturnLastName ‘matt clingan’,@lastname output
select
@lastname

Advertisements

Written by matt

July 3, 2007 at 6:02 am

Posted in T-Sql

2 Responses

Subscribe to comments with RSS.

  1. […] I discussed how to call a stored procedure within a stored procedure.

  2. another way to do this is by using table variables

    declare @tbl table (strname varchar(200))

    insert into @tbl
    execute dummyReturnLastName ‘matt clingan’,@lastname

    select * from @tbl

    matt

    August 1, 2008 at 3:28 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: