0

我有一个存储过程(SP1),我希望它调用另一个存储过程(SP2)。

代码 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

代码 SP1

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

4

2 回答 2

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
于 2013-05-12T13:18:48.563 回答
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
于 2013-05-12T13:31:16.793 回答