我有一个存储过程(SP1),我希望它调用另一个存储过程(SP2)。
ALTER PROCEDURE dbo.addOrderStatus
(
@orderID INT,
@statusID INT,
@startTime DATETIME,
@endTime DATETIME,
@isActive BIT
)
AS
BEGIN
SET NOCOUNT ON
INSERT INTO Order_Status
(orderID, statusID, startTime, endTime, isActive) VALUES
(@orderID, @statusID, @startTime, @endTime, @isActive)
END
ALTER PROCEDURE [dbo].addNewOrder
(
@customerID int,
@restaurantID int,
@cost float,
@addressID int,
@ID INT OUTPUT
)
AS
SET NOCOUNT OFF;
INSERT INTO [Order]
([customerID], [restaurantID], [cost], [addressID])
VALUES (@customerID, @restaurantID, @cost, @addressID);
set @ID = @@IDENTITY
EXEC addOrderStatus @ID, @statusID = 1, @startTime = SYSDATETIME , @endTime = NULL, @isActive = TRUE
我得到了这个例外
Error converting data type nvarchar to datetime.
我怎么解决?
感谢提前
代码是
DECLARE @startTime DATETIME
SET @startTime = SYSDATETIME
EXEC addOrderStatus @ID, @statusID = 1, @startTime , @endTime = NULL, @isActive = TRUE
现在我知道我必须使用此表单name , value
答案 0 :(得分:0)
编辑 - 错误的部分已删除
首先声明你的变量,设置内容然后传递它们。
DECLARE @starttime datetime;
DECLARE @statusID int;
DECLARE @endTime datetime;
DECLARE @isActive int;
SET @startTime = GETDATE();
SET @statusID = 1;
SET @endTime = null;
SET @isActive = 1;
EXEC addOrderStatus @ID, @statusID, @startTime , @endTime, @isActive
答案 1 :(得分:0)
而不是:
EXEC addOrderStatus @ID, @statusID = 1, @startTime = SYSDATETIME , @endTime = NULL, @isActive = TRUE
试试这个:
declare @sDate datetime;
set @sDate=getdate();
EXEC addOrderStatus @ID, @statusID = 1, @startTime = @sDate , @endTime = NULL, @isActive = TRUE