Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Pass empty parameters to stored procedure

Author  Topic 

duanecwilson
Constraint Violating Yak Guru

273 Posts

Posted - 2009-08-13 : 10:51:25
EXEC MyStoredProcedure 'abc', 'def', 'hij'
If I want to leave the first one out, I found out I have to type in NULL:
EXEC MyStoredProcedure NULL, 'def', 'hij'

I tried this:
EXEC MyStoredProcedure , 'def', 'hij'
but it didn't work. I was hoping to just use a comma for the blank parameter.
It is used as a filter, so if I use '', then it attempts to filter an empty string, not a NULL. But I am testing for NULL to see if anything was supplied. If I leave them all out, it runs fine.
Is there a way to supply NULL parameters by just leaving them out, or do I have to type in NULL? (unless they are all NULL)

Duane

YellowBug
Aged Yak Warrior

616 Posts

Posted - 2009-08-13 : 11:23:48
Try this:
EXEC MyStoredProcedure @Parameter2 = 'def', @Parameter3 = 'hij'
Go to Top of Page

duanecwilson
Constraint Violating Yak Guru

273 Posts

Posted - 2009-08-14 : 11:11:49
Thank you. I will try that.

Duane
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2009-08-14 : 17:59:02
The definition of the stored procedure needs to have a default value if you to omit it in the calling sqquence.

create MyProc @P1 int = Null, @P2 varchar(50) as ....

exec MyProc @P2 = 'xyz'



=======================================
Men build too many walls and not enough bridges. -Isaac Newton, philosopher and mathematician (1642-1727)
Go to Top of Page
   

- Advertisement -