Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Optional Parameters in Functions

Status
Not open for further replies.

Shaggs

Programmer
Aug 26, 2003
25
AU
can you have optional parameters in sql server functions?
 
Optional" parameters?... not really, but you can set up default values for your parameters, but you have to pass them as 'DEFAULT' to the function:
[tt]
CREATE FUNCTION myFunction(@param INT = 1) RETURNS INT
AS
BEGIN
RETURN @param
END
GO

SELECT dbo.myFunction(DEFAULT)
UNION
SELECT dbo.myFunction(5)
GO
DROP FUNCTION myFunction
[/tt]
-dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top