• vahid.arr (3/22/2013)


    this my table with test data

    You've forgotten the expected results based on your sample data that was requested. You've not mentioned whether or not you tried the code I posted.

    So converting my code to use your table, you'd do something like this: -

    SELECT KarmandID, EnterTime, ExitTime,

    CONVERT(VARCHAR(5), diffSeconds / 3600) + ':' +

    RIGHT('0' + CONVERT(VARCHAR(5), diffSeconds % 3600 / 60),2) + ':' +

    RIGHT('0' + CONVERT(VARCHAR(5), diffSeconds % 60),2) AS [Time Difference],

    CONVERT(VARCHAR(5), [diffSeconds multiplied 30] / 3600) + ':' +

    RIGHT('0' + CONVERT(VARCHAR(5), [diffSeconds multiplied 30] % 3600 / 60),2) + ':' +

    RIGHT('0' + CONVERT(VARCHAR(5), [diffSeconds multiplied 30] % 60),2) AS [Time Difference Multiplied 30]

    FROM (SELECT KarmandID, EnterTime, ExitTime,

    DATEDIFF(s, EnterTime, ExitTime) AS diffSeconds,

    DATEDIFF(s, EnterTime, ExitTime) * 30 AS [diffSeconds multiplied 30]

    FROM [Karmand]

    ) a;

    Which returns: -

    KarmandID EnterTime ExitTime Time Difference Time Difference Multiplied 30

    --------- ---------------- ---------------- --------------- -----------------------------

    103 09:15:00.0000000 16:30:00.0000000 7:15:00 217:30:00

    104 07:15:00.0000000 14:05:00.0000000 6:50:00 205:00:00


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/