0

我想將存儲過程結果用於另一個存儲過程的內部,如子查詢。可能嗎..?將存儲過程結果集轉換爲另一個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 
+0

您可以在查詢中使用函數的最佳實踐但不是proc。 GetDynamicUsers中的GetDynamicPassword並將其存儲在臨時表中。爲什麼不能這樣做。 – KumarHarsh

回答

2

這樣做是創建一個函數,然後調用它在你的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 
相關問題