Ask a Question related to Microsoft SQL / MS SQL Server, Design and Development.

  1. #1

    Default Summing time......

    Hi
    I have a field which is a Date/Time field....
    It actually only makes use of the Time portion, and this holds a duration of
    an activity....

    However, I want to have a query which returns the total duration of all the
    times in the records.
    Is there an easy way, to SUM date/time fields (or just the time elements),
    to give the total duration of all the records??

    Thanks


    Paul


    Paul Aspinall Guest

  2. Similar Questions and Discussions

    1. summing data based on football seasons
      Hi, I have 3 tables season, fixture and scorers. season is defined as: seasonID int(11) name varchar(20) with data like:
    2. Summing a repeated table...
      Hi, Rob, I applied your extension to my application and it's great. Thank you! By the way, how can I format the "RR Totaliser Display"? I want it to...
    3. Summing Variable in CF 4.0
      Hi Folks OK - I know I'm still using an old version of CF but I'm hoping someone can help me. Is there anyway to sum dyanmic variables in a...
    4. Summing a column and displaying in the footer
      I would like to sum a column in my dataset and have it displayed at the bottom of the datagrid in the footer. How do I do that?
    5. Summing three levels in ASP
      Hi I have three levels of cost items, like the following: TOP_LEVEL SECOND_LEVEL cost_item1 cost_item2 etc... TOP_LEVEL2
  3. #2

    Default Re: Summing time......

    select sum(dtefld)

    a datetime is just a decimal number with the integer part the date and
    the decimal part the time. As you are just using the time the integer
    part will be 0 (19000101) and you can just sum the fields to give a
    total time.



    Nigel Rivett (SQL Server MVP)
    [url]www.nigelrivett.net[/url]

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Nigel Rivett Guest

  4. #3

    Default Re: Summing time......

    select sum(dtefld)

    a datetime is just a decimal number with the integer part the date and
    the decimal part the time. As you are just using the time the integer
    part will be 0 (19000101) and you can just sum the fields to give a
    total time.

    except that sum will not take a datetime so you can

    select convert(datetime,sum(convert(decimal(18,5),dtefld) ))
    But I suspect that this will lose some precision.

    But maybe better to take advantage of the factr that a date is 2 4 byte
    integer values - the second being the time so

    select
    convert(datetime,convert(binary(8),sum(convert(int ,convert(binary(4),
    dtefld))))) from #a


    Nigel Rivett (SQL Server MVP)
    [url]www.nigelrivett.net[/url]

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Nigel Rivett Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139