Solved

Optional parameters in CREATE FUNCTION.

Posted on 2004-04-02
6
442 Views
Last Modified: 2007-12-19
why optional parameters can't work on CREATE FUNCTION?

ex.

CREATE FUNCTION dbo.MyFunc
      (@param1       datetime,
      @param2      int = 0)      -- default value is zero.
 .
 .
 .

dbo.MyFunc(getdate())

it prompt an error "An insufficient number of arguments were supplied for the procedure or function dbo.MyFunc."

is there a way to use optional parameters in CREATE FUNCTION?
0
Comment
Question by:doc_jer
  • 4
  • 2
6 Comments
 
LVL 26

Accepted Solution

by:
Hilaire earned 50 total points
ID: 10739336
User - defined functions don't support optional parameters
0
 
LVL 26

Expert Comment

by:Hilaire
ID: 10739344
Other known limitations are
- you can't use exec() inside a UDF
- you can't use non-deterministic functions (like getdate())
0
 

Author Comment

by:doc_jer
ID: 10739348
so its only stored proc
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 26

Expert Comment

by:Hilaire
ID: 10739361
Yes, only in stored procedures

another limitation of UDFs is that you can't insert/update/delete
0
 

Author Comment

by:doc_jer
ID: 10739362
ok thanks...
0
 
LVL 26

Expert Comment

by:Hilaire
ID: 10739375
>>another limitation of UDFs is that you can't insert/update/delete<<
Actually you can insert/update/delete , but only in #temp tables or tabel @variables
created inside the scope of the function
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now