Convert Access Function to SQL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mich

    Convert Access Function to SQL

    I'm going crazy trying to convert an Access Function to SQL.
    From what I've read, it has to be done as a stored procedure.
    I'm trying to take a field that is "minutes.second s" and convert it to minutes.

    This is what I have in Access:

    Function ConvertToTime (myAnswer As Variant)
    Dim myMinutes
    myMinutes-(((((myAnswer * 100)Mod 100/100/0.6)+(CInt(myAn swer-0.4))))
    ConvertToTime =(myMinutes)
    End Function

    When I tried to modify it in SQL:

    CREATE PROCEDURE [OWNER].[PROCEDURE NAME] AS ConvertToTime
    Function ConvertToTime(m yAnswer As Variant)
    Dim myMinutes
    myMinutes = (((((myAnswer * 100)Mod 100)/100/0.6)+9CInt(myAn swer-0.4))))
    ConvertToTime=( myMinutes)
    End

    I get an error after ConverToTime.
  • David Portas

    #2
    Re: Convert Access Function to SQL

    Transact-SQL is not VB!

    If you are using SQL2000 you can create a user-defined function:

    CREATE FUNCTION dbo.ConvertToMi nutes (@minsec DECIMAL(5,2))
    RETURNS DECIMAL(5,2)
    BEGIN
    RETURN ROUND(@minsec,0 ,1)+(@minsec-ROUND(@minsec,0 ,1))*10/6
    END

    GO

    SELECT dbo.ConvertToMi nutes(100.30)

    Result:

    -------
    -100.50

    (1 row(s) affected)

    --
    David Portas
    ------------
    Please reply only to the newsgroup
    --


    Comment

    • William Cleveland

      #3
      Re: Convert Access Function to SQL

      Mich wrote:[color=blue]
      >
      > CREATE PROCEDURE [OWNER].[PROCEDURE NAME] AS ConvertToTime
      > Function ConvertToTime(m yAnswer As Variant)
      > Dim myMinutes
      > myMinutes = (((((myAnswer * 100)Mod 100)/100/0.6)+9CInt(myAn swer-0.4))))
      > ConvertToTime=( myMinutes)
      > End
      >[/color]
      T-SQL uses "Return <value>" for functions, like C or Java, not
      "<Function Name> = <value>", like VB (including Access) or Pascal.

      Bill

      Comment

      Working...