一尘不染

如何在选择查询中执行存储过程

sql

SELECT col1,
       col2,
       col3,

EXEC GetAIntFromStoredProc(T.col1) AS col4
     FROM Tbl AS T
     WHERE (col2 = @parm) 

如何在SQL Server 2008中编写此SQL查询?


阅读 192

收藏
2021-05-23

共1个答案

一尘不染

这是解决方案。

首先我们创建一个函数

CREATE FUNCTION GetAIntFromStoredProc(@parm Nvarchar(50)) RETURNS INTEGER

AS
BEGIN
   DECLARE @id INTEGER

   set @id= (select TOP(1) id From tbl where col=@parm)

   RETURN @id
END

然后我们进行选择查询

Select col1, col2, col3,
GetAIntFromStoredProc(T.col1) As col4
From Tbl as T
Where col2=@parm
2021-05-23