This question already has an answer here:
这个问题在这里已有答案:
- Execute a Stored Procedure in a SELECT statement 4 answers
- 在SELECT语句中执行存储过程4个答案
I want to call the stored procedure in select statement of SQL server. When I call the stored procedure it is generating error.
我想在SQL服务器的select语句中调用存储过程。当我调用存储过程时,它会产生错误。
What can be wrong in the below select statement??
下面的select语句可能有什么问题?
Select i.item as col1, exec StoreProc_name(i.item) as col2
from tbl_item as i where i.item>100
This is not working. What is the right way to call stored procedure in SQL server.
这不起作用。在SQL Server中调用存储过程的正确方法是什么。
1 个解决方案
#1
0
declare @table table as (
col2 as int
);
insert @table(col2)
exec StoreProc_name i.item;
This of course doesn't work as part of a query, but only in a (not recommended) cursor - so check into defining a Inline Table-Valued Function to replace your stored procedure.
这当然不能作为查询的一部分,但只能在(不推荐)游标中使用 - 因此请检查定义内联表值函数以替换存储过程。
Note that your stored procedure should begin with this statement in order to be usable by OLEDB and ADO:
请注意,您的存储过程应以此语句开头,以便OLEDB和ADO可以使用:
set nocount on;
#1
0
declare @table table as (
col2 as int
);
insert @table(col2)
exec StoreProc_name i.item;
This of course doesn't work as part of a query, but only in a (not recommended) cursor - so check into defining a Inline Table-Valued Function to replace your stored procedure.
这当然不能作为查询的一部分,但只能在(不推荐)游标中使用 - 因此请检查定义内联表值函数以替换存储过程。
Note that your stored procedure should begin with this statement in order to be usable by OLEDB and ADO:
请注意,您的存储过程应以此语句开头,以便OLEDB和ADO可以使用:
set nocount on;