question

rsheik avatar image
rsheik asked

Why Iam unable to pass a non null value as input to a stored procedure ??

Hello... I have a stored procedure for which there is an input parameter of type **int**. like **create proc myProcedure @myInput int as begin ..........my logic end** but now .. I dont want to allow a null value to my input parameter. I tried like this. **create proc myProcedure @myInput int not null as begin ..........my logic end It is not working... I know that i can restrict null values in my logic..i want know why we cannot give **not null** at procedure creation time.
parameters
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

What would you expect to happen if this were possible and the parameter was set to null? An error message?
0 Likes 0 ·

1 Answer

· Write an Answer
JohnM avatar image
JohnM answered
As far as I know, there isn't a way to do this in the manner you're looking for. You would either need to validate that there isn't a NULL value either in the calling application or within the logic in your procedure. I found similar questions and they pretty much suggest the same thing: https://stackoverflow.com/questions/330303/how-to-restrict-null-as-parameter-to-stored-procedure-sql-server http://www.sqlservercentral.com/Forums/Topic560409-149-1.aspx Hope this helps!
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.