How can I join on a stored procedure?

后端 未结 9 2083
渐次进展
渐次进展 2020-12-25 10:48

I have a stored procedure that takes no parameters, and it returns two fields. The stored procedure sums up all transactions that are applied to a tenant, and it returns the

9条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-25 11:45

    insert the result of the SP into a temp table, then join:

    CREATE TABLE #Temp (
        TenantID int, 
        TenantBalance int
    )
    
    INSERT INTO #Temp
    EXEC TheStoredProc
    
    SELECT t.TenantName, t.CarPlateNumber, t.CarColor, t.Sex, t.SSNO, t.Phone, t.Memo,
        u.UnitNumber, p.PropertyName
    FROM tblTenant t
    INNER JOIN #Temp ON t.TenantID = #Temp.TenantID
    ...
    

提交回复
热议问题