"Incorrect Syntax near S" in Stored Procedure I'm creating a SQL Server stored procedure and getting error 


  Incorrect Syntax near S


I'm not able to find the exact reason of the error.

CREATE PROCEDURE RPT_IVR_CALL_SUMMARY
    (@i_APPLICATION_ID     VARCHAR(50),
     @i_SESSION_ID         VARCHAR(50),
     @i_UNIQUERIGHT_ID     VARCHAR(50),
     @i_CALLINGPROC        VARCHAR(50),
     @i_FROM_DATE          VARCHAR(50),
     @i_T@o_DATE           VARCHAR(50),
     @i_CATEGORY           XML,
     @i_CIRCLE             XML,
     @i_SUMMARIZED_BY      VARCHAR(50),
     @i_REPORT_USER        VARCHAR(50),
     @o_ERRORCODE          INT OUTPUT ,
     @o_ERRORDESCRIPTION   VARCHAR(4000) OUTPUT)
AS
    DECLARE @v_ENABLEAUDIT VARCHAR(15),
            @v_QUERY VARCHAR(15);
    DECLARE @I_SYSDATE      DATETIME;
BEGIN
    SET NOCount ON;

    BEGIN TRY
        SET @I_SYSDATE = GETDATE()

        SELECT
            CODE Code,
            CODE Description,
            SUM(OFFEREDCALLS) CallCount
        FROM
            (SELECT
                 (CASE WHEN @i_SUMMARIZED_BY = 'Circle' THEN CALLCIRCLECODE
                                  ELSE VXMLSERVER END)                CODE,
                 OFFEREDCALLS
             FROM
                 TBL_SUMMRESOLUTION
             WHERE
                 (CAST(CONVERT(VARCHAR(13), SUMMDATE, 103) AS DATETIME) - CAST(CONVERT(VARCHAR(13), @i_FROM_DATE, 103) AS DATETIME)) &gt;= 0 
                 AND (CAST(CONVERT(VARCHAR(13), SUMMDATE, 103) AS DATETIME) - CAST(CONVERT(VARCHAR(13), @i_T@o_DATE, 103) AS DATETIME)) &lt;= 0          
                 AND (CATEGORY IN (SELECT ROLEGROUPLIST.ID.query('Code').value('.','VARCHAR(50)') AS CATEGORYCODE 
                                   FROM  @i_CATEGORY.nodes('/Categories/Category') AS ROLEGROUPLIST(ID)) 
                 AND (CALLCIRCLECODE IN (SELECT  ROLEGROUPLIST.ID.query('Code').value('.','VARCHAR(50)') AS CIRCLECODE 
                                         FROM  @i_CIRCLE.nodes('/Circles/Circle') AS ROLEGROUPLIST(ID))
                ) S
   GROUP BY
       CODE;
 END TRY
 BEGIN CATCH
        SET @o_ERRORCODE = ERROR_NUMBER()
        SET @o_ERRORDESCRIPTION = ERROR_MESSAGE()
          IF UPPER(@v_ENABLEAUDIT) = 'ENABLED' 
            EXEC PROC_AUDIT_TRAIL @i_APPLICATION_ID,@i_SESSION_ID, @I_SYSDATE, @o_ERRORDESCRIPTION, @v_QUERY, @i_REPORT_USER , @i_UNIQUERIGHT_ID,'RPT_IVR_CALL_SUMMARY'

          SELECT NULL
END CATCH  
END
You should add 2 more parentheses -- ))) S. Try it!