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
 General SQL Server Forums
 New to SQL Server Programming
 Need SP to read inputs dynamically

Author  Topic 

Srinivas007
Starting Member

7 Posts

Posted - 2013-03-09 : 09:20:32
Hello everyone,

I am new to developing the stored procedures. So can anyone help me in developing the below requirement? Any help is appreciated.

There is a SQL table t1 with m*n columns in which one column contains SQL query for each row.
I have written a stored procedure to read that query and execute the respective query to give the output results. This stored procedure (find below for SP) works only by giving the inputs manually.
-----------------------------------------------------------------
Alter Procedure sp1 @primarykey int, @query nvarchar(max) OUTPUT
AS
Select @query= Query from t1 where primarykey=@primarykey
GO

Declare @query nvarchar(max)
Exec sp1 @primarykey=26, @query= @query OUTPUT
exec sp_executesql @query
-----------------------------------------------------------------

What I need is....

I want to execute the above stored procedure by passing the @primarykey ID dynamically (like @primarykey=1,2,3....max) to get the results of all the query's of each row.

Can anyone help with the code?

Thanks,
Sri

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-09 : 10:48:21
are the query resultsets identical? if not how would you combine results into single row?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Srinivas007
Starting Member

7 Posts

Posted - 2013-03-11 : 04:58:01
For each query (i.e. for each primary key), the result sets will be different. I want to run multiple queries one by one by taking the input (PrimaryKey) dynamically.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-11 : 06:24:00
so you want them as different resultsets in output?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -