title: How to set Out Parameter value from a query in Stored Procedure
body: <p>I have Stored Procedure, and I want out parameter <code>@OUT_TOTALROWS</code></p>
  
  <pre><code>ALTER PROCEDURE [dbo].[P_SOMEPROC](@IN_USERID INT,  
                                          @IN_SEARCHFILTER VARCHAR(50),
                                          @IN_DELIVERYSTATUS TINYINT,
                                          @IN_PAGESKIP INT = NULL,
                                          @IN_PAGENEXT INT = NULL)
                                          @OUT_TOTALROWS INT OUTPUT) --TOTAL ROWS OUT HERE
  
  -- ******** HOW TO SET @OUT_TOTALROWS FROM HERE?
  SELECT COUNT(*) OVER() AS TotalRows, --IS THERE A BEGIN WAY? DONT WANT THIS
         P.NAME
      FROM SOMETABLE PM
      join SOMETABLE_2 P ON P.ID = PM.ID
      WHERE PM.UserID = @IN_USERID AND 
      PM.DeliveryStatus = @IN_DELIVERYSTATUS AND
      (CONCAT(P.FirstName, ' ', P.LastName) LIKE '%' + @IN_SEARCHFILTER + '%' OR
      PM.Message LIKE '%' + @IN_SEARCHFILTER + '%')
      ORDER BY PM.ScheduledDate DESC OFFSET @IN_PAGESKIP ROWS FETCH NEXT @IN_PAGENEXT ROWS ONLY;
  </code></pre>
  
  <p>So, I want to know total rows before offset is applied and want to return that as Output Parameter, along with the data retrieved.</p>
  
  <p>Is there any better way to get set <code>@OUT_TOTALROWS</code>?</p>