使用sql查询指定存储过程参数

时间:2013-04-02 15:27:51

标签: sql sql-server-2008 select stored-procedures

让我先说我对SQL不是很了解,这使得难以找到答案。我可能使用了错误的'措辞'。

给出以下查询来执行存储过程:

USE MyDB
SET NOCOUNT ON
    EXECUTE dbo.adm_ExecuteProcedure
        @installationID           = 12345,
        @monthOf                  = '03/01/2013'
GO

我可以使用select语句动态查找12345吗?以下不起作用,但我正在尝试做。

USE MyDB
SET NOCOUNT ON
    EXECUTE dbo.adm_ExecuteProcedure
        @installationID           = (select id from installs where name = 'foo'),
        @monthOf                  = '03/01/2013'
GO

我无权编辑存储过程。

4 个答案:

答案 0 :(得分:4)

declare @id int;

select  @id = id 
from    installs 
where   name = 'foo';

EXECUTE dbo.adm_ExecuteProcedure
    @installationID           = @id,
    @monthOf                  = '03/01/2013';

答案 1 :(得分:0)

好吧,你可以这样做,但是在调用存储过程的代码中......甚至在存储过程的任何查询中,在这种情况下你根本不需要参数......

答案 2 :(得分:0)

尝试将其存储在变量中(语法取决于您的数据库系统)

答案 3 :(得分:0)

您可以做的是声明变量并从select语句中选择该变量中的installationId,然后在执行存储过程时使用该变量。你有没有。