如何在选择查询中执行存储过程 [英] How to execute a stored procedure inside a select query

查看:22
本文介绍了如何在选择查询中执行存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SELECT col1,
       col2,
       col3,

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

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

How to write this SQL query in SQL Server 2008?

推荐答案

感谢 @twoleggedhorse.

Thanks @twoleggedhorse.

这是解决方案.

  1. 首先我们创建了一个函数

  1. First we created a function

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

  • 然后我们进行选择查询

  • then we do the select query

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

  • 这篇关于如何在选择查询中执行存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆