Optional Parameters with User Defined Functions
Does anyone know if it's possible to have an optional input parameter with
Functions (just as you can with Stored Procedures) .
Backround:
The reason I'm asking is that I am writing a function to convert a time that
is passed in as a paramater into a propriatory format (FIX format for anyone
that is in brokerage) In addition to the formating of the date/time, the
time needs to be converted to GMT time. I'm doing that by comparing the
hour difference between the current time (using getdate()) and the current
GMT time (using getutdate()) . I add this result to the date passed in to
get that time in GMT time then convert the new datetime to the custom format.
I tried calling getdate() and getutcdate() from within the Function, but
I soon found out that those functions can not be called from within a Function.
I then tried using those functions as optional paramaters. Here's the syntax:
CREATE FUNCTION BOSSConvertDateToTranTime
(
@DateToConv datetime,
@CurDateTime datetime = getdate,
@GMTDateTime datetime = getutcdate
)

