SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need SP to read inputs dynamically
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Srinivas007
Starting Member

India
7 Posts

Posted - 03/09/2013 :  09:20:32  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 03/09/2013 :  10:48:21  Show Profile  Reply with Quote
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

India
7 Posts

Posted - 03/11/2013 :  04:58:01  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 03/11/2013 :  06:24:00  Show Profile  Reply with Quote
so you want them as different resultsets in output?

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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000