title: SEC_TO_TIME SQL Server
body: <p>This function converts second to time in SQL Server:</p>
  
  <pre><code>Create function [dbo].[SEC_TO_TIME](@seconds1 INT)
  returns VARCHAR(8)
  As
  Begin 
      DECLARE @time1 VARCHAR(8);
      SET @time1  SELECT CONVERT(VARCHAR(8), DATEADD(second, @seconds1, 0), 108);
      return @time1;
  end 
  GO
  </code></pre>
  
  <p>But I get an error:</p>
  
  <blockquote>
    <p>Msg 156, Level 15, State 1, Procedure SEC_TO_TIME, Line 7<br>
    Incorrect syntax near the keyword 'SELECT'.</p>
  </blockquote>
  
  <p>I tried executing this query which works fine.</p>
  
  <pre><code>SELECT CONVERT(VARCHAR(8), DATEADD(second, 180, 0), 108);
  </code></pre>
  
  <p>Can you please help me to fix this error?</p>