0

I have this stored procedure

ALTER PROC myProcedure 
    @day VARCHAR (6) = NULL
as

Now if I call it like this

EXEC myProcedure @day= ''

What will be the result of @day? Will it be empty string or NULL?

My theory is, if the parameter was omitted completely, it would be NULL, but now it will be empty string. Can anyone confirm?

1 Answer 1

1

If you pass an empty string, the param value is empty string. You can easily check by selecting the variable as shown below

IF OBJECT_ID('myProcedure') IS NOT NULL
DROP PROC myProcedure 
GO
CREATE PROC myProcedure 
    @day VARCHAR (6) = NULL
as
BEGIN
    SELECT @day as param
END
GO
--Returns empty string in output
EXEC myProcedure @day= ''

--Returns NULL as output
EXEC myProcedure

Note: the reason NULL is returned is because the parameter is defaulted to NULL in the procedure parameter definition. If the default was omitted, the EXEC myProcedure will return an error.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. That's what I thought, but I couldn't check it myself for various reasons (permissions, etc.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.