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)
 EXEC sp

Author  Topic 

george
Starting Member

4 Posts

Posted - 2009-01-20 : 12:32:18
Hello -

I want to execute a stored procedure I have by passing in the values of the result set returned from a select statement.

I am doing this right now by using the following code
INSERT INTO LogInsert SELECT id, action from actiontable

I really want to clean this up and use a stored procedure so I do not have to write this code everywhere.

SELECT id, action from actiontable - would return multiple records

EXEC LogInsert SELECT id, action from actiontable

CREATE PROCEDURE [dbo].LogInsert
(
@Id int, @Action int = NULL
)

INSERT INTO LogInsert (id, action) VALUE (@Id, @Action )

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-20 : 12:36:13
then what you should be writing is a table valued UDF so that you can use it in select staements. Writing a procedure would require you to loop over table and pass values one by one whereas if its a table valued udf you can just apply it over entire table records by using CROSS APPLY.
Go to Top of Page
   

- Advertisement -