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 2000 Forums
 SQL Server Development (2000)
 stored proc parameter default

Author  Topic 

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2003-10-25 : 17:33:14
Hi,

If I have a parameter in my stored procedure that I may not use in my application, can I set a default for it?

I think i've seen this before:

@szCountry VARCHAR(80) = Null,


Does this mean that if I don't give a value for this parameter it will default to NULL so my INSERT statement will work so long as the field takes a NULL value?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-10-25 : 18:10:24
Yes, but if you like you can also modify your procedure to change this to another value:

CREATE PROCEDURE myProc @szCountry varchar(80)=Null AS
SET @szCountry=IsNull(@szCountry, 'Nowhere')
....rest of code goes here


So if you don't pass anything for that parameter (or pass a null explicitly) it will substitute 'Nowhere' as a value.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2003-10-25 : 18:26:33
What's wrong with
CREATE PROCEDURE myProc
@szCountry varchar(80)= 'Nowhere'
AS

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2003-10-31 : 16:16:47
I see, that's a neat trick. Thanks.
Go to Top of Page

Sitka
Aged Yak Warrior

571 Posts

Posted - 2003-11-01 : 17:55:14
When I build procs for finance stuff I almost always include
@leftdate datetime = <a datetime value way in the past (ie.1900-01-01....) >,
@rightdate datetime = <a date 500 years from now>
Seems every money thing eventually needs to range on date so even if not needed they are at the ready. Does this make sense to anyone or is it stupid.
Go to Top of Page
   

- Advertisement -