VistaDB 6
VistaDB / Developer's Guide / SQL Reference / Stored Procedures and User-Defined Functions / SQL User Defined Function Example
In This Topic
    SQL User Defined Function Example
    In This Topic

    T-SQL Functions can also be created using the CREATE FUNCTION syntax.

    CREATE FUNCTION
    Copy Code
    CREATE FUNCTION [MyRound]
    (
        @Operand Decimal,
        @Places Int
    )
    RETURNS DECIMAL
    AS
    BEGIN
        DECLARE @x decimal;
        DECLARE @i int;
        set @x = @Operand * power(10,@Places);
        set @i = @x;
        set @x = @i + iif((@x - @i) >= .5,1,0);
        set @x = @x / power(10,@Places);
        RETURN(@x);
    END
    

    This creates a function that implements a custom round based upon the POWER and the places argument.

    SELECT MYROUND( 2.569, 2 ); -- 2.57 
    SELECT MYROUND( 2.5649, 2 ); -- 2.56
    

    You can then use it in your own application using the above syntax.

    Functions in Data Builder

    The user defined functions show up in Data Builder under the programmability area.

    See Also