title: msg 102 incorrect syntax
body: <p>Below is the drop and create script for my stored procedure.While executing this script on Database i'm getting error </p>
  
  <p><code>Msg 102, Level 15, State 1, Line 18
  Incorrect syntax near 'Date'.
  Msg 105, Level 15, State 1, Line 35
  Unclosed quotation mark after the character string '
  END
  '.</code></p>
  
  <p>i tried with adding-removing quotation marks but did not worked.</p>
  
  <p>can anyone tell what i have to do in order to execute the script successfully</p>
  
  <pre><code>/****** Object:  StoredProcedure [dbo].[MY_PROC]    Script Date: 9/12/2013 3:31:17 PM ******/
  IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MY_PROC]') AND type in (N'P', N'PC'))
  DROP PROCEDURE [dbo].[MY_PROC]
  GO
  /****** Object:  StoredProcedure [dbo].[MY_PROC]    Script Date: 9/12/2013 3:31:17 PM ******/
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MY_PROC]') AND type in (N'P', N'PC'))
  BEGIN
  EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[MY_PROC]
  (@P_Date DateTime=null)
  AS
  BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;
  
      DECLARE @M_DATE_PARAM DATETIME
      DECLARE @M_PREVIOUS_DATE DATETIME
      DECLARE @M_TODAYS_DATE DATETIME
  
      IF @P_Date IS NULL
      SET @P_Date=GetDate()
  
      PRINT 'Date passed as a parameter -' + CAST(@P_Date AS varchar(100))   
        BEGIN TRY
              BEGIN TRANSACTION REIMBURSEMENT_TRN  
  
                  BEGIN                   
                     -- my statements go here which do not cause any error
  
                  END
                   PRINT 'SUCCESS: Procedure Success'
              COMMIT TRANSACTION ;
          END TRY
          BEGIN CATCH
              PRINT 'ERROR: Procedure Fail'
              PRINT ERROR_MESSAGE()
              PRINT ERROR_LINE()
              ROLLBACK TRANSACTION ;
          END CATCH
          PRINT 'Procedure Complete'
  END
  </code></pre>