2016-01-23 88 views
0

當我運行代碼下面我得到的錯誤消息:過程或函數期望沒有提供的參數?

消息201,過程stp_DespatchedJob,行0過程或函數 「stp_DespatchedJob」預計參數「@JobStatusId」,這是不 供給

set ANSI_NULLS ON 
set QUOTED_IDENTIFIER ON 
go 


ALTER PROCEDURE [dbo].[stp_DespatchedJob] 
(
    @jobId as bigint, 
    @DriverId int, 
    @HasPda bit, 
    @enablePda bit, 
    @IsAdvanceJob bit, 
    @IsAutodespatchedJob bit, 
    @Controller varchar(100), 
    @JobStatusId int 

) 
AS 
Begin 

    if(@enablepda=1 and @haspda=1) 
    BEGIN 
     UPDATE BOOKING 
      SET [email protected],JobOfferDateTime=getdate() 
       ,[email protected],despatchdatetime=getdate() 
       ,Despatchby = @Controller 
     where [email protected] 


    END 

    ELSE 
    BEGIN 

     declare @fleetMasterId int 
     select @fleetMasterId=fleetMasterId from fleet_DriverQueueList where [email protected] and status=1 


     UPDATE BOOKING 
      SET BookingStatusId=2,[email protected],despatchdatetime=getdate(),[email protected],Despatchby = @Controller 
      where [email protected] 

     END 


    if(@IsAdvanceJob=1 and @IsAutodespatchedJob=1) 
    BEGIN 

     Update booking_autodespatch set despatched=1 where [email protected] 
    END 

End 

這是什麼意思?爲什麼我得到這個錯誤?如何擺脫這一點?

+0

你得到什麼錯誤訊息? – dev

+0

消息201,過程stp_DespatchedJob,行0過程或函數「stp_DespatchedJob」需要參數「@JobStatusId」,但未提供 –

+0

存儲的特效跟隨延遲名稱編譯,這意味着對象的存在將不檢查,直到runtime.So我跑你的代碼,我能夠創建並修改它,而無需發佈任何問題。您是否嘗試執行SP – TheGameiswar

回答

0

由於所有過程參數是強制性的,有正確調用它的兩種方式:

1)直接(不推薦)

EXEC dbo.stp_DespatchedJob 1,2,1,1,1 ,1, 'CTRL',7

2)使用named parameters(推薦)

EXEC [dbo].[stp_DespatchedJob] 
    @jobId = 1, 
    @DriverId = 2, 
    @HasPda = 1, 
    @enablePda = 1, 
    @IsAdvanceJob = 1, 
    @IsAutodespatchedJob = 1, 
    @Controller = 'ctrl', 
    @JobStatusId = 7 

未能爲您的所有參數提供值將導致類似於您收到的錯誤。如果你有一些值幾乎始終是相同的(如JobStatusId = 1),你可以在程序原型的默認值指定:

ALTER PROCEDURE [dbo].[stp_DespatchedJob] 
(
    @jobId as bigint, 
    @DriverId int, 
    @HasPda bit, 
    @enablePda bit, 
    @IsAdvanceJob bit, 
    @IsAutodespatchedJob bit, 
    @Controller varchar(100), 
    @JobStatusId int = 1 
) 
AS 

,你不再需要調用時@JobStatusId提供一個值程序。

+0

謝謝SOOO MUCH SIR,這個固定對我來說,對已經被困數月,你是一個明星! –

相關問題