DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Eoin Beck Guest

    Optional Parameters with User Defined Functions


    Hello !

    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
    )

  2. #2
    Join Date
    Jun 2006
    Posts
    1

    Using Standard Function from within User Defined Function in SQL

    Well you can ofcourse call getdate and getutcdate from within the user defined function the point is that user defined functions are scalar objects you need to call them like...

    dbo.getutcdate()

    dbo.getdate()


    Regards

    Arunav
    Microsoft .Net Guru (www.arunav.net)

  3. #3
    Join Date
    Feb 2006
    Posts
    55
    Quote Originally Posted by arunav
    Well you can ofcourse call getdate and getutcdate from within the user defined function the point is that user defined functions are scalar objects you need to call them like...

    dbo.getutcdate()

    dbo.getdate()


    Regards

    Arunav
    Microsoft .Net Guru (www.arunav.net)
    You can't call non-deterministic system functions from a user defined function. There are some workarounds to get the current date - one of which is to pass it as a param.
    David Wiseman
    MCSE (2000/2003), MCSA (2003), MCDBA
    www.wisesoft.co.uk


  4. #4
    Join Date
    Feb 2006
    Posts
    55
    Here are some other workarounds:

    http://www.aspfaq.com/show.asp?id=2439

    I've seen a few others used too but can't remember them off the top of my head...
    David Wiseman
    MCSE (2000/2003), MCSA (2003), MCDBA
    www.wisesoft.co.uk


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links