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 |
|
SamC
White Water Yakist
3467 Posts |
Posted - 2005-05-31 : 10:17:27
|
Ever notice that defaults can be supplied on UDF parameters?CREATE FUNCTION dbo.UDF_EmailCDOSYS ( @From VARCHAR(100), @To VARCHAR(100), @Subject VARCHAR(100), @Body VARCHAR(4000), @CC VARCHAR(100) = '', @BCC VARCHAR(100) = '') What is the point of a default if T-SQL requires all the parameters present to invoke the function? |
|
|
gpl
Posting Yak Master
195 Posts |
Posted - 2005-05-31 : 11:30:46
|
| Does the default get used if you supply a NULL value ? |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2005-05-31 : 14:13:56
|
| You have to supply the key word DEFAULT if you don't supply the parameter.CODO ERGO SUM |
 |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2005-05-31 : 14:31:14
|
quote: Originally posted by Michael Valentine Jones You have to supply the key word DEFAULT if you don't supply the parameter.
Argh ! I didn't know...Adding "DEFAULT" makes it a little convenient to evolve a function to include a new parm. I ended up adding the new parm, appendinging the function name with a suffix "_2", then "stubbing" the predecessor function name to call the new function.If that makes sense... |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2005-05-31 : 14:39:28
|
Just remember that for a function, you must supply either a value, or the key word DEFAULT (if you have defined a default value). It does not work like a stored procedure where you can add a new parameter, and don't have to change all the calls to it, as long as the paramater has a default value.In practice, this means that adding a parameter to a widely used function can be a lot of work, so you should put more work into it upfront, deciding what parameters you really need.quote: Originally posted by SamC
quote: Originally posted by Michael Valentine Jones You have to supply the key word DEFAULT if you don't supply the parameter.
Argh ! I didn't know...Adding "DEFAULT" makes it a little convenient to evolve a function to include a new parm. I ended up adding the new parm, appendinging the function name with a suffix "_2", then "stubbing" the predecessor function name to call the new function.If that makes sense...
CODO ERGO SUM |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-06-03 : 04:43:31
|
10 extra paramters "for future use" ?? Kristen |
 |
|
|
|
|
|
|
|