简体   繁体   中英

SQL 2000: Stored Procedures Error : Procedure or Function 'name' expects parameter '@param', which was not supplied

I have a stored procedure which is declared as follows:

    ALTER PROCEDURE dbo.thisProc
 @ID int,@TypeID int, @DocID int, @Section varchar(10)

What I need is to be able to do this:

If @ID is supplied, execute a particular if block if @ID is not supplied then move check if @TypeID is input and then execute another if block.

I don't want to write multiple sql queries to deal with different inputs/page sections that a user is viewing.

Thanks.

SAMPLE CODE:

    CREATE PROCEDURE GetArticle
    @ID int,@DoTypeID int, @DocID int, @Sec varchar(10)
AS
IF @ID IS NOT NULL AND , @DocID IS NOT NULL  AND @Sec = 'inner'
BEGIN
  SELECT  "my query is here" 

WHERE Articles.ID = @ID AND Articles.DocID = @DocID  

END
ELSE IF @ID IS NULL AND @DocID  IS NULL  AND @Sec  = 'list'
BEGIN
    EXEC GetDocList @DocTypeID
END

ELSE IF @ID IS NULL AND @DocID  IS NULL  AND @Sec = 'full'
BEGIN
EXEC GetDocList @DocTypeID
END

Just give @id a default value of null. Eg

@id int = null

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM