Hi everyone,

If you work with development, you’ll understand me… sometimes, your procedures must have optional params. It’s very common in languages like… VB, Java, C#, Progress ABL, and so on.

In T-Sql isn’t diff, and this is an example of optional params.
It’s just use =NULL in the param…

Proc
–DROP PROC DBO.AAA_TESTE
CREATE PROC DBO.AAA_TESTE
(@NUM1 INTEGER
,@NUM2 INTEGER
,@NUM3 INTEGER = NULL)
AS

IF @NUM3 IS NULL
BEGIN
SELECT @NUM1 + @NUM2
END
ELSE
BEGIN
SELECT @NUM1 + @NUM2 + @NUM3
END

Testing
EXEC AAA_TESTE 1,2
EXEC AAA_TESTE 1,2,1

Both scripts work, with 2 and with 3 params.

That’s all.