Passing dynamic parameters to a stored procedure in SQL Server 2008

Posted by themhz on Stack Overflow See other posts from Stack Overflow or by themhz
Published on 2012-03-29T10:28:35Z Indexed on 2012/03/29 11:29 UTC
Read the original article Hit count: 227

I have this procedure that executes another procedure passed by a parameter and its parameters datefrom and dateto.

CREATE procedure [dbo].[execute_proc] 
@procs varchar(200),
@pdatefrom date,
@pdateto date
as

exec @procs  @datefrom=@pdatefrom,@dateto=@pdateto

But I need to also pass the parameters dynamically without the need to edit them in the procedure. For example, what I am imagining is something like this

 CREATE procedure [dbo].[execute_proc] 
    @procs varchar(200),
    @params varchar(max)
 as
    exec @procs @params 

where @params is a string like @param1=1,@param2='somethingelse'

Is there a way to do this?

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server