title: How to write a SQL Server scalar function to calculate the sum?
body: <p>I'm having an issue with SQL Server 2008, I want to write a function that returns the sum of a specific column, the code goes like this:</p>
  
  <pre><code>CREATE FUNCTION [dbo].[GetIssuesSum](@i int)
  RETURNS int
  AS
  BEGIN
      DECLARE @IssueSum int
  
      SELECT SUM (@IssueSum = Quantity) 
      FROM Issue
  
      RETURN @IssueSum
  
  END
  </code></pre>
  
  <p>When I try to execute it, SQL Server 2008 throws this error</p>
  
  <blockquote>
    <p>Msg 102, Level 15, State 1, Procedure GetIssuesSum, Line 15<br>
    Incorrect syntax near '='.</p>
  </blockquote>
  
  <p>Any suggestions? Thanks in advance</p>