• !Aaron Aardvark! (1/9/2012)


    Just for interest's sake, here's the in-line function written to use SQL Server 2012:

    CREATE FUNCTION dbo.agent_datetime_inline

    (

    @Date integer,

    @Time integer

    )

    RETURNS TABLE WITH SCHEMABINDING

    AS RETURN

    SELECT

    DATETIMEFROMPARTS

    (

    @Date / 10000,

    @Date / 100 % 100,

    @Date % 100,

    @Time / 10000,

    @Time / 100 % 100,

    @Time % 100,

    0

    ) AS date_time

    Test results using Jeff's rig:

    Michael's code: 1155ms

    New function: 670ms

    Now THAT would make a cool "spackle" article... you should go for it, Paul. Thanks for the "preview".

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)