title: How to assign value to a variable from a select statement inside stored procedure?
body: <p>I have this stored procedure and for debugging purposes, I want to know what value is getting returned, in order to do that I have created a table and logging the value returned from a query but I am not sure on how to get the value in that select statement for loggin.</p>
  
  <p>My stored procedure (modified for demonstration):</p>
  
  <pre><code>BEGIN
      DECLARE @SID INT 
  
      BEGIN TRY
          SELECT 
              SL.[Column1], SL.[Column2], SL.[Column3], 
              SMD.[Column4], SMD.[Column5]
              (some more logic)               
  
          BEGIN 
              DECLARE @ProcedureName6 NVARCHAR(168) = 'dbo.MYSP',
                      @ErrorMessage6 NVARCHAR(4000)
  
              SELECT @ErrorMessage6 = 'SID is:' +  CAST(@SID AS VARCHAR)
  
              EXEC [Log].[ErrorLoger] @ProcedureName6, @ErrorMessage6
          END
      END TRY
      BEGIN CATCH
          //Some Logic
      END CATCH
  END
  </code></pre>
  
  <p>I actually want <code>SL.[Column2]</code> to be set in <code>@SID</code> for logging.</p>