Re: EXECUTE 'tsqlstring' with parameters
From: Russ Ferrill (rferrill_at_paracominc.com)
Date: 08/25/04
- Previous message: cknobs: "Nightly maintenance failures"
- In reply to: Darious: "Re: EXECUTE 'tsqlstring' with parameters"
- Next in thread: Anith Sen: "Re: EXECUTE 'tsqlstring' with parameters"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 25 Aug 2004 16:11:20 GMT
I've tried using exec by itself, exec sp_executesql with an embedded exec
string and sp_executesql with parameter substitution. They all work fine
until I need to execute a stored procedure that uses an OUTPUT parameter.
Here's what I'm trying to do. I have a procedure that does a table lookup to
determine which stored procedure to execute. Once the stored procedure is
chosen, the parameters to this procedure are always the same. The challenge
I am facing is that some of these parameters are OUTPUT parameters and I
have been unsuccessful passing an OUTPUT parameter to a stored procedure
unless I know the name of the procedure at compile time. If the name of the
stored procedure is determined dynamically I have been unable to pass it an
OUTPUT parameter. Do you have any ideas on how I might do that? All
suggestions will be appreciated. Thanks.
Russ
"Darious" <news@areyoukidding.com> wrote in message
news:4ccni011quqe32hrjl1nkqfupba5tdn52a@4ax.com...
> Hiya,
>
> I've done this in the past, the best method I came up with was the
> build the entire exec spname parm1, parm2 etc into the nvarchar and
> then call sp_executesql with the whole string, e.g.
>
> declare @strsql as nvarchar(100)
>
> set @qt = ''''
> set @strsql = 'EXEC ' + @spname + @parm1 + ', ' @parm2
>
> exec sp_executesql @strsql
>
> If your parameters are strings then you'll have to include the '
> character in the sql string to do this use '''' I usually store this
> in a char(1) called @qt, it makes the string cleaner.
>
> Perhaps not he cleanest approach, but it will work.
>
> Darious
>
>
> On Tue, 24 Aug 2004 19:45:51 GMT, "Russ Ferrill"
> <rferrill@paracominc.com> wrote:
>
> >I've looked at the discussion of the execute command in BOL but it says
> >nothing about passing parameters. I would like to use:
> >EXEC ( @spname @parm1, @parm2 OUTPUT ) where @spname is the name of the
> >stored procedure, @parm1 is an input parameter and @parm2 is an output
> >parameter. When I try this I get an error saying that I need to declare
> >@parm1, which I have done prior to executing the statment. If I use the
same
> >command with the actual name of the stored procedure in place of @spname
it
> >works just fine, but I really need to be able to select the procedure
> >dynamically. If there is a way to do this I would greatly appreciate some
> >suggestions. Thanks very much.
> >
> >Russ
> >"Roji. P. Thomas" <lazydragon@nowhere.com> wrote in message
> >news:%23nPdbqgiEHA.1644@tk2msftngp13.phx.gbl...
> >> > I'd like to be abe to dynamically build a tsql command to execute a
> >stored
> >> > procedure that takes parameters. Is this possible?
> >>
> >> YES :)
> >>
> >> --
> >> Roji. P. Thomas
> >> Net Asset Management
> >> https://www.netassetmanagement.com
> >>
> >>
> >> "Russ Ferrill" <rferrill@paracominc.com> wrote in message
> >> news:IkKWc.12845$Ib1.6074@newssvr22.news.prodigy.com...
> >> > I'd like to be abe to dynamically build a tsql command to execute a
> >stored
> >> > procedure that takes parameters. Is this possible?
> >> >
> >> >
> >>
> >>
> >
>
- Previous message: cknobs: "Nightly maintenance failures"
- In reply to: Darious: "Re: EXECUTE 'tsqlstring' with parameters"
- Next in thread: Anith Sen: "Re: EXECUTE 'tsqlstring' with parameters"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|