title: SQL Function returning sum value of all rows
body: <p>I have two tables, Job table and Item table. I have created a function where I'm trying to return a sum value of customer price for each individual job. Instead it returns a total sum of all jobs combined. The following is my function that I have created:</p>
  
  <pre><code>CREATE FUNCTION dbo.ApprvStatTotal(@JobNumber nvarchar(255)) 
  RETURNS int  
  AS  
  BEGIN    
      DECLARE @ int    
  
      SELECT @ = Sum(CustmPrice)
      FROM dbo.Job 
      INNER JOIN dbo.Item ON dbo.Job.JobNumber = dbo.Item.JobNumber
      WHERE dbo.Job.JobNumber = dbo.Item.JobNumber 
        AND CustmApprvStat = 'Closed' 
         OR CustmApprvStat = 'Approved'
  
      RETURN @
  End
  </code></pre>
  
  <p>I would like to get a total sum of of customer price of each individual job instead of overall total of all jobs, if that makes sense. If someone could help me with this, I would greatly appreciate it. Thanks  </p>