title: How to get Loan Status from Deduction table using sql Stored Procedure
body: <p>Loan Table</p>
  <p><a href="https://i.stack.imgur.com/dgzm4.png" rel="nofollow noreferrer">Above image loan table information </a></p>
  <p>Deduction table</p>
  <p><a href="https://i.stack.imgur.com/3IS2U.png" rel="nofollow noreferrer">Deduction Table Information</a></p>
  <p>Above Using 2 tables I need to get a loan status for all particular loan in loan table
  Below Stored Procedure  I used to getting a loan information where I need to alter to set the status for  all particular loans</p>
  <p>Stored Procedure for Getting a loan Status</p>
  <pre><code>ALTER PROCEDURE [dbo].[spGetLoan]
      -- Add the parameters for the stored procedure here
      @CompanyID  INT,
      @LoanID     BIGINT,
      @EmployeeID BIGINT
  
  AS
  BEGIN
      
      SET NOCOUNT ON;
      SET CONCAT_NULL_YIELDS_NULL OFF;
      
  
  
      SELECT  e.EmployeeNumber, (e.FirstName + ' ' + e.LastName) AS EmployeeName,s.SubCompanyName,l.* 
      FROM [dbo].[Loans] l    
      INNER JOIN [dbo].[Employees] e ON l.EmployeeID = e.EmployeeID
      inner join SubCompanies s on s.SubCompanyID=l.CompanyID
      WHERE ISNULL(l.IsActive, 1) = 1 
      --AND l.CompanyID = @CompanyID
      AND (l.LoanID = @LoanID OR ISNULL(@LoanID, 0) = 0)
      AND (l.EmployeeID = @EmployeeID OR ISNULL(@EmployeeID, 0) = 0)
  
  
  END
  </code></pre>