【发布时间】:2013-12-20 06:31:24
【问题描述】:
我想在另一个存储过程中使用存储过程结果,例如子查询。有可能吗..?
下面的示例代码:密码生成逻辑在一个 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
【问题讨论】:
-
您可以在查询中使用函数,但不能在 proc 中使用。在 GetDynamicUsers 中执行 GetDynamicPassword 并将其存储在临时表中。为什么不能这样做。
标签: sql sql-server sql-server-2008 sql-server-2005 stored-procedures