title: Error: A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations
body: <p>When i run the following query, an error occurred saying:</p>
  
  <blockquote>
    <p>A SELECT statement that assigns a value to a variable must not be
    combined with data-retrieval operations.</p>
  </blockquote>
  
  <p>How should I fix this?</p>
  
  <p>Here is the query:</p>
  
  <pre><code>DECLARE @loanInstallmet float
  
  SELECT TOP (1) 
      loan.loanID,members.offno AS OfficialNumber,
      loan.loanAmount,
      loan.interestRate,
      loan.NoOfInstallment,
      loanHistory.presentInstallmentNo,
      loanHistory.dateBalanceUpdate,
      (loanHistory.presentInstallmentNo + 1) AS InstallmentNo, 
      members.monthllyContribution AS MonthlyContribution, 
      @loanInstallmet = 
          CASE 
              WHEN  loan.remarks = 'Half' THEN ROUND(loanHistory.balanceAmount/ (loan.NoOfInstallment-loanHistory.presentInstallmentNo ), 0) 
              ELSE ROUND((loan.loanAmount / loan.NoOfInstallment), 0)
          END, 
      CASE 
          WHEN  loanHistory.presentInstallmentNo % 12 = 0 THEN ROUND(((loan.loanAmount-loanHistory.balanceAmount) * loan.interestRate / 1200), 0)
          ELSE ROUND((loan.loanAmount * loan.interestRate / 1200), 0)
      END AS MonthlyInterest, 
      LEFT(DATENAME(MONTH,Getdate()),3)as recMonth,
      year(GETDATE())as recYear,
      loan.isRecovered as LoanIsRecovered,
      members.memberIsActive,
      loanHistory.status,
      ROUND((loanHistory.balanceAmount-@loanInstallmet), 0) AS BalanceAmount,
      loan.remarks
  FROM loan
  INNER JOIN members 
      ON loan.offNo = members.offno
  INNER JOIN loanHistory 
      ON members.offno = loanHistory.offNo
      AND loan.loanID = loanHistory.loanID
  WHERE 
      loan.isRecovered = 0
      AND members.memberIsActive = 1  
  order by loanHistory.presentInstallmentNo DESC
  </code></pre>