1

我有这样的存储过程:

create PROCEDURE [dbo].[Test1]  
   @startdate datetime(100),  
   @enddate datetime(100)
   set  date1 = CONVERT(datetime, @startdate + ' 00:01:00', 120)
   set   date2 = CONVERT(datetime, @enddate + ' 00:23:59', 120)  
as  
begin  
  select t.PlateNo 
  from Transaction_tbl t  
  WHERE dtime between @date1 + ' 00.01.00.00' 
    AND @date2 + ' 23:59.59.00'  
end

执行此操作时收到两条错误消息

关键字“set”附近的语法不正确。

必须声明标量变量@date1

4

2 回答 2

0

尝试这个:-

create PROCEDURE [dbo].[Test1]  
   @startdate varchar(100),  
   @enddate varchar(100)
as 
declare @date1 datetime
declare @date2 datetime
   set  @date1 = CONVERT(datetime, @startdate + ' 00:01:00', 120)
   set   @date2 = CONVERT(datetime, @enddate + ' 00:23:59', 120)  

begin  
  select t.PlateNo 
  from Transaction_tbl t  
  WHERE dtime between @date1 + ' 00.01.00.00' 
    AND @date2 + ' 23:59.59.00'  
end
于 2013-08-25T18:20:46.180 回答
0

我想你的意思是:

create PROCEDURE [dbo].[Test1]  
   @startdate varchar(100),  
   @enddate varchar(100)
as  
begin  
   declare @date1 datetime = CONVERT(datetime, @startdate + ' 00:01:00', 120);
   declare @date2 datetime = CONVERT(datetime, @enddate + ' 00:23:59', 120);

   select t.PlateNo 
   from Transaction_tbl t  
   WHERE dtime between @date1 AND @date2; 
end;

但是,我认为您最好遵循我对上一个问题的回答中的建议并将参数作为date.

于 2013-08-25T18:26:09.717 回答