• opc.three (3/15/2013)


    PS Forgot to mention the function is undocumented so take that into consideration.

    It's a cough scalar function too.

    Combine the best bits of Lynn's and Scott's solutions and roll them into an inline TVF:

    CREATE FUNCTION [dbo].[IF_Agent_Datetime]

    (

    @Date INT,

    @Time INT

    )

    RETURNS TABLE WITH SCHEMABINDING AS

    RETURN

    (

    SELECT DatetimeValue =

    DATEADD(SECOND,@Time % 100,

    DATEADD(MINUTE,@Time % 10000 / 100,

    DATEADD(HOUR,@Time/10000,

    CAST(CAST(@Date AS CHAR(8)) AS DATETIME))))

    )

    GO

    SELECT *

    FROM dbo.IF_Agent_Datetime (20130314, 123011)

    2013-03-14 12:30:11.000

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden