title: SQL: Msg 156, Level 15, State 1 :Incorrect syntax near the keyword 'END'
body: <p>Ok i have 2 questions 1) I've googled that error(in title) but I cant seem to get it to help me, my proc:</p>
  
  <pre><code>CREATE PROCEDURE [dbo].[p_Target]
  AS
  BEGIN
  SET NOCOUNT ON
  
      CREATE TABLE #tmp1 
      (
          AUD_ID BIGINT,
          RowCounter BIGINT,
          DistinctCounter BIGINT,
          NACounter BIGINT,
          Total BIGINT,
          [Status] VARCHAR(MAX)
      )
     INSERT INTO #tmp1 EXEC [p_GetCompleteIncompleteNaOverviewSCORE] 
  DECLARE @Total AS INT
  
      SELECT @Total = COUNT(*)
      FROM (
      SELECT CASE WHEN CONVERT(DATETIME,CONVERT(CHAR(10),DATEADD(DAY,0,t2.AUD_TargetDate), 101)) &lt; CONVERT(DATETIME,CONVERT(CHAR(10),DATEADD(DAY,0,GETDATE()), 101))
              THEN 'Over Due: '
              ELSE 'On Time: ' END AS [Target Status]
              FROM #tmp1 t1 INNER JOIN dbo.Audit t2
              ON t1.AUD_ID = t2.AUD_ID
              WHERE t1.[Status] = 'Open') DER 
  
      SELECT ([Target Status] + '' + CAST(COUNT(*) AS NVARCHAR(255))  + ' of ' + CAST(@Total AS NVARCHAR(255))) AS TargetStatus, (SELECT COUNT(*)) * 100 / (SELECT ([Target Status] + '' + CAST(COUNT(*) AS NVARCHAR(255))) AS [Count]
      FROM (
      SELECT CASE WHEN CONVERT(DATETIME,CONVERT(CHAR(10),DATEADD(DAY,0,t2.AUD_TargetDate), 101)) &lt; CONVERT(DATETIME,CONVERT(CHAR(10),DATEADD(DAY,0,GETDATE()), 101))
              THEN 'Over Due: '
              ELSE 'On Time: ' END AS [Target Status]
              FROM #tmp1 t1 INNER JOIN dbo.Audit t2
              ON t1.AUD_ID = t2.AUD_ID
              WHERE t1.[Status] = 'Open') DER
      GROUP BY [Target Status] 
      END
  GO
  </code></pre>
  
  <p>I've tied adding ) to <code>NVARCHAR(255))) AS [Count]</code> but still errors, </p>
  
  <p>2)I need to get <code>AS [Count]</code> as a percentag, if anyone can help? That is my try code maybe i am on the right track.?</p>