在日期差异过程中开始关键字相关错误

时间:2016-01-05 07:30:08

标签: sql-server stored-procedures

赞美是成功的,但是当我执行此代码时,它显示错误"关键字' BEGIN'"附近的语法不正确..并且可能是以下代码

SET @TEMPSELECT=(SELECT Cast(Abs(Datediff(day, @EndDate, @StartDate)) AS VARCHAR(100)) AS day)

PRINT @TEMPSELECT 

procedure date difference

1 个答案:

答案 0 :(得分:0)

试试这个,

CREATE PROCEDURE Prc_datechecking
AS
  BEGIN
      DECLARE @StartDate  DATETIME='04/07/2015',
              @EndDate    DATETIME='04/09/2015',
              @TEMPSELECT NVARCHAR(50)=''

      SET @TEMPSELECT=(SELECT Cast(Abs(Datediff(day, @EndDate, @StartDate)) AS VARCHAR(100)) AS day)

      PRINT @TEMPSELECT
  END

EXEC Prc_datechecking 

这在SQL Server 2012中运行良好