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