How can I join on a stored procedure?

后端 未结 9 2074
渐次进展
渐次进展 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:24

    Why not just performing the calculation in your SQL?

    SELECT 
      t.TenantName
      , t.CarPlateNumber
      , t.CarColor
      , t.Sex
      , t.SSNO
      , t.Phone
      , t.Memo
      , u.UnitNumber
      , p.PropertyName
      , trans.TenantBalance
    FROM tblTenant t
         LEFT JOIN tblRentalUnit u ON t.UnitID = u.ID
         LEFT JOIN tblProperty p ON u.PropertyID = p.ID
         INNER JOIN (
           SELECT tenant.ID AS TenantID, SUM(ISNULL(trans.Amount,0)) AS TenantBalance 
           FROM tblTenant tenant
                LEFT JOIN tblTransaction trans ON tenant.ID = trans.TenantID
           GROUP BY tenant.ID
         ) trans ON trans.ID = t.ID
    ORDER BY 
      p.PropertyName
      , t.CarPlateNumber
    

提交回复
热议问题