Results 1 to 2 of 2

Thread: Getting different results

  1. #1

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Getting different results

    Hi,

    Im trying to calculate how many hrs a user wroked weekly, however i'm getting different results

    1) i'm trying to get the time using the 'between' function for a specfic week

    Code:
    SELECT       [userID]     , CAST(SUM(workingtime) / 60 AS varchar(5)) + ':' + RIGHT('0' + CAST(SUM(workingtime) % 60 AS varchar(2)), 2)
      FROM yyyyy
      where   datee between '01/04/2014' and '01/11/2014'
      group by userID
    for user A i'm getting = 58 for that specific week

    2)i tried to do the same thing but with a different code, and i get a different result for user A which is 52hrs for that specific week

    Code:
    SELECT  userID,  CONVERT(varchar(50), (DATEADD(dd, @@DATEFIRST - DATEPART(dw, datee), datee)), 101), CAST(SUM(workingtime) / 60 AS varchar(5)) + ':' + RIGHT('0' + CAST(SUM(workingtime) % 60 AS varchar(2)), 2) AS Expr1
    FROM     yyy
    GROUP BY userID, CONVERT(varchar(50), (DATEADD(dd, @@DATEFIRST - DATEPART(dw, datee), datee)), 101)
    I tried to alternate the first and last day of the week but still i don't get the same result?
    I'm not sure why i'm getting different results, any help will be appreciated.

    Thanks

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Getting different results

    Post sample data. People need to see how the data is organized in your table (data type included).
    Last edited by leinad31; Feb 17th, 2014 at 01:26 AM. Reason: additional comment

Posting Permissions

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



Click Here to Expand Forum to Full Width