[英]Stored Procedure resultset into sub query in another SP
我想将存储过程结果用于另一个存储过程的内部,例如子查询。 可能吗..?
下面的示例代码:在一个sp中创建密码生成逻辑:
Create Procedure GetDynamicPassword
@Password out
As
Begin
-- Password generate Logic createhere
-- More than 100 line to generate password logic
End
我想将以上结果用于另一个SP。
无法使用临时表,因为我一次需要这么多记录的结果。
我想在下面的sp中使用上面的sp。
Create Procedure GetDynamicUsers
As
Begin
Select a.col1, b.col2 , c.col3...
( I want to uses password here from above SP )
( like exec GetDynamicPassword) As Password
from Table1 As a
inner join Table2 As b on a.Code = b.Code
inner join Table3 As c on a.Code = c.Code
inner join Table4 As d on a.Code = d.Code
End
将存储过程GetDynamicPassword
重写为标量值的用户定义函数 。
然后,您可以直接在select语句中使用该函数。
这样做的最佳实践是创建一个函数,然后在您的SP中调用它
Create function GetDynamicPassword
returns varchar(100)
As
Begin
-- Password generate Logic createhere
-- More than 100 line to generate password logic
End
然后在下面的SP中使用它
Create Procedure GetDynamicUsers
As
Begin
Select a.col1, b.col2 , c.col3...,
dbo.GetDynamicPassword() As Password
from Table1 As a
inner join Table2 As b on a.Code = b.Code
inner join Table3 As c on a.Code = c.Code
inner join Table4 As d on a.Code = d.Code
End
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.