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.
| Author |
Topic |
|
ingineu
Yak Posting Veteran
89 Posts |
Posted - 2005-09-15 : 12:06:28
|
| Is there an option in a stored procedure whereby a parameter can be flagged as optional? I have a stored procedure with 2 parameters, Product and Date, and I would like to be able to just pass the Product, or pass Product and Date from an Access project. Is this possible? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-09-15 : 12:47:05
|
| Yes it's possible. Just provide a default value for it.Tara |
 |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2005-09-15 : 13:37:10
|
| [code]CREATE PROCEDURE HooHah ( -- Whimsy@Parm1 VARCHAR (100) ,@Parm2 INT = 0, -- default value if not passed@Parm3 VARCHAR (200) OUTPUTASIF @Parm1 = 'Hoo' BEGIN SET @Parm3 = 'Hah' + CAST(@Parm2 AS VARCHAR) END[/code] |
 |
|
|
ingineu
Yak Posting Veteran
89 Posts |
Posted - 2005-09-15 : 14:30:24
|
| Can I set the default value to NULL? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-09-15 : 14:35:37
|
| Yes.Tara |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2005-09-15 : 23:54:49
|
If you set the default value to NULL, you will want to test for NULL OR a value in your WHERE, etc clauses. Remember NULL to anything, even NULL, is always false. That's unless you have your ANSI_NULLS option set incorrectly of course. MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
|
|
|