1
我已經在Azure上建立在我的示例數據庫中的存儲過程使用DATEADD:SQL試圖在存儲過程中
CREATE PROCEDURE SalesLT.InsertOrderHeader(@OrderDate AS DATETIME=NULL, @DueDate AS DATETIME=NULL, @CustomerID AS INT=NULL)
AS
DECLARE @SalesOrderID INT = NEXT VALUE FOR SalesLT.SalesOrderNumber
IF @OrderDate IS NULL
BEGIN
SET @OrderDate = GETDATE()
END
INSERT INTO SalesLT.SalesOrderHeader(SalesOrderID,OrderDate,DueDate,CustomerID,ShipMethod)
VALUES (@SalesOrderID,@OrderDate,@DueDate,@CustomerID,'CARGO TRANSPORT 5')
PRINT @SalesOrderID
這創造了罰款,但是當我試圖把它我想日期的一週現在:
EXEC SalesLT.InsertOrderHeader @DueDate= DATEADD(dd,7,getDate()) , @CustomerID=1
這沒有奏效。這些錯誤說,它說:「DD」它期待(或選擇,併爲獲取日期的結束括號一樣有什麼地方錯了,
[附近有語法錯誤)'調用與GETDATE storedproc(https://stackoverflow.com/questions/2399104/incorrect-syntax-near-calling-storedproc-with-getdate) –
你的可能的複製不能將函數調用作爲參數傳遞給存儲過程。而是使用中間變量 https://stackoverflow.com/questions/2399104/incorrect-syntax-near-calling-storedproc-with-getdate –