You are here: Re: Can a stored procedure parameter be optional « MsSQL Server « IT news, forums, messages
Re: Can a stored procedure parameter be optional

Posted by Erland Sommarskog on 03/08/06 00:13

CK (c_kettenbach@hotmail.com) writes:
> I want the procedure to check for the existence of a paramter and if it is
> there, it will process these instructions, otherwise it will process these
> instructions. Any ideas? Thanks for your advice.

Yes, consider:

CREATE PROCEDURE some_sp @a int,
@b int = 465 AS
PRINT @a + @b
go
EXEC some_sp 1

Prints 466. You can even say:

EXEC some_sp 1, DEFAULT

to explicitly say that you want the default value to be used.

The most commonly used default value for stored procedure parameters is
probably NULL.

Note that there is no way in the stored procedure to tell whether
the parameter was actually specified in the call, or whether the
default was used. That is, inside some_sp you cannot tell the
difference between

EXEC some_sp 1

and

EXEC some_sp 1, 465


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация