Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

call sp from another sp

 
   Database Help (Home) -> Programming RSS
Next:  Linked Servers / OLE DB Jet4.0 request fails!  
Author Message
GW

External


Since: Mar 22, 2010
Posts: 3



(Msg. 1) Posted: Mon Apr 12, 2010 7:54 am
Post subject: call sp from another sp
Archived from groups: microsoft>public>sqlserver>programming (more info?)

how to call the following sp from another SP?

CREATE PROCEDURE general_select @tblname nvarchar(128),
@key varchar(10),
@debug bit = 0 AS
DECLARE @sql nvarchar(4000)
SET @sql = 'SELECT col1, col2, col3
FROM dbo.' + quotename(@tblname) + '
WHERE keycol = @key'
IF @debug = 1 PRINT @sql
EXEC sp_executesql @sql, N'@key varchar(10)', @key = @key

Help is much appreciated. thank you.

 >> Stay informed about: call sp from another sp 
Back to top
Login to vote
Uri Dimant

External


Since: Aug 24, 2003
Posts: 1744



(Msg. 2) Posted: Mon Apr 12, 2010 11:25 am
Post subject: Re: call sp from another sp [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

CREATE PROCEDURE usp_main
@param1 nvarchar(128),
@param2 varchar(10)
AS
EXEC general_select @tblname =@param1,@key =@param2

--Usage
EXEC usp_main @param1 ='TBL',@param2 ='BLABLA

'




"GW" wrote in message

> how to call the following sp from another SP?
>
> CREATE PROCEDURE general_select @tblname nvarchar(128),
> @key varchar(10),
> @debug bit = 0 AS
> DECLARE @sql nvarchar(4000)
> SET @sql = 'SELECT col1, col2, col3
> FROM dbo.' + quotename(@tblname) + '
> WHERE keycol = @key'
> IF @debug = 1 PRINT @sql
> EXEC sp_executesql @sql, N'@key varchar(10)', @key = @key
>
> Help is much appreciated. thank you.

 >> Stay informed about: call sp from another sp 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
call order - If a VIEW and a STORED PROCEDURE exist and have the same identical name - is there a particular call sequence that SQL SERVER uses - in other words if the particular name is called up in code - does SQL pull the view first or the SP first.

how do i call a stored proc that looks like this from ADO... - how do i call a stored proc that looks like this from ADO.NET? ALTER PROCEDURE new_pzGetIDList ( @foo varbinary(8) ) i have it as a System.Byte[4] in C#

Performance issues because of recursive call. - Hi reposting, hoping to get a response, I am helping rewrite a process to help optimize a process that is causing deadlocks and is taking a long time. Let say you have a table like the following. Table1 ID ParentID field1 field2 field3 field4 ..

Multiple Inserts - One SP Call - I want to store a "document MRU list" in a database (table "DocMRU"). The list in question really has nothing to do with the data model otherwise implemented in the database. Each list entry would be 3 integers - so 3 int columns i...

How to call a View from a Stored Procedure - First off, I realize that this question may have been answered elsewhere, but I could not find it - if it is out there somewhere, I would appreciate a link. That much said, here is my scenario. I have created a SQL View that gets a set of records based...
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]