0

我有一个有问题的 sybase 存储过程。

在这里,如果我直接使用插入语句,插入可以完美地工作,如图所示:

insert 
  into dbo.StudentData
     ( studID
     , studLetters
     , studCode 
     , studTelecast 
     , studName
     , monthCode
     , reportDate
     , startTime
     , endTime
     , startDateTime
     , endDateTime
     , cost
     , duration
     , creationTime
     )
values
     ( 113
     , 'ABCD'
     , 222
     , 333
     , 'One'
     , 02
     , getDate()
     , getdate()
     , getdate()
     , getdate()
     , getdate()
     , 999
     , 11
     , getdate()
     )
     ;

但是,如果我使用存储过程,我会收到以下错误:

[EXEC - 0 row(s), 0.000 secs]  [Error Code: 102, SQL State: 42000]  Incorrect syntax near ')'.

exec dbo.sp_loadStudData(113, 'ABCD', 222, 333, 'One', 02, getDate(), getdate(), getdate(), getdate(), getdate(), 999, 11, getdate() ) 

我无法找出问题所在,但存储过程已成功创建,没有任何错误。存储的 Proc 如下:

create proc dbo.sp_loadStudData
(
@studID int,                   
@studLetters varchar(255),
@studCode int,
@studTelecast int,
@studName varchar(25),
@monthCode int,
@reportDate datetime,
@startTime datetime,
@endTime datetime,
@startDateTime datetime,
@endDateTime datetime,
@cost int,
@duration int,
@creationTime datetime
)
as
begin
set nocount on


insert into dbo.StudentData(studID,studLetters,studCode ,studTelecast ,studName ,monthCode,reportDate,startTime,endTime,startDateTime,endDateTime,cost,duration,creationTime)
values(@studID,@studLetters,@studCode ,@studTelecast ,@studName ,@monthCode,@reportDate,@startTime,@endTime,@startDateTime,@endDateTime,@cost,@duration,@creationTime)

end
go
EXEC sp_procxmode 'dbo.sp_loadStudData', 'unchained'
go
IF OBJECT_ID('dbo.sp_loadStudData') IS NOT NULL
    PRINT '<<< CREATED PROCEDURE dbo.sp_loadStudData >>>'
ELSE
    PRINT '<<< FAILED CREATING PROCEDURE dbo.sp_loadStudData >>>'
go
GRANT EXECUTE ON dbo.sp_loadStudData TO developers
go
GRANT EXECUTE ON dbo.sp_loadStudData TO web_group
go
GRANT EXECUTE ON dbo.sp_loadStudData TO crd_group
go
GRANT EXECUTE ON dbo.sp_loadStudData TO wd_group
go
4

2 回答 2

1

我不是 Sybase 方面的专家,但肯定在 SQL Server 中,您需要首先将 getdate() 返回值存储在一个变量中。

即你不能...

EXEC MyProc getdate(), getdate(), getdate()

但是你可以

DECLARE @Now DATETIME
SET @Now = GETDATE()
EXEC MyProc @Now, @Now, @Now 
于 2013-04-25T13:27:07.267 回答
1

在此处删除大括号并运行

exec dbo.sp_loadStudData 113, 'ABCD', 222, 333, '一', 02, getDate(), getdate(), getdate(), getdate(), 999, 11, getdate()

于 2013-04-25T16:01:41.193 回答