Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Sum the Counts

Sum the Counts

Scheduled Pinned Locked Moved Database
databasesql-serversysadminhelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Elizabeth Rani
    wrote on last edited by
    #1

    Hi All, Iam new to database. Here iam using sql server 2000. i want to sum the counts from a table. I need this to calculate the employees who have come late in a week/month. Example: I have table such as Table1:tbl_attandence(it contains the employee id and the intimings and outtime) Fields:empcode,intime,outime Eg: EMP001,11/1/2011 09:30:45 AM,11/30/2011 06:30:15 PM I am attaching my code such that it return the count but iam unable to sum the values because it is showing the result as shown below DECLARE @actualTime DATETIME DECLARE @lateTime DATETIME SELECT @actualTime = '9:41' Select @lateTime ='10:00' select count(convert(varchar,intime,105)) as dates,CONVERT(VARCHAR(5),intime,108) AS Hours from tbl_attendance where empcode='EMP001'; and intime between '2011-11-01' and '2011-11-30' and CONVERT(VARCHAR(5),intime,108) >=@actualTime and CONVERT(VARCHAR(5),intime,108) <= @lateTime group by CONVERT(VARCHAR(5),intime,108) OytPut: days intime 1 09:41 1 09:44 1 09:46 2 09:53 1 09:54 Now i need to sum all the days and get the sum as 7 Please suggest that how can i do this task any help will be appreciated

    M 1 Reply Last reply
    0
    • E Elizabeth Rani

      Hi All, Iam new to database. Here iam using sql server 2000. i want to sum the counts from a table. I need this to calculate the employees who have come late in a week/month. Example: I have table such as Table1:tbl_attandence(it contains the employee id and the intimings and outtime) Fields:empcode,intime,outime Eg: EMP001,11/1/2011 09:30:45 AM,11/30/2011 06:30:15 PM I am attaching my code such that it return the count but iam unable to sum the values because it is showing the result as shown below DECLARE @actualTime DATETIME DECLARE @lateTime DATETIME SELECT @actualTime = '9:41' Select @lateTime ='10:00' select count(convert(varchar,intime,105)) as dates,CONVERT(VARCHAR(5),intime,108) AS Hours from tbl_attendance where empcode='EMP001'; and intime between '2011-11-01' and '2011-11-30' and CONVERT(VARCHAR(5),intime,108) >=@actualTime and CONVERT(VARCHAR(5),intime,108) <= @lateTime group by CONVERT(VARCHAR(5),intime,108) OytPut: days intime 1 09:41 1 09:44 1 09:46 2 09:53 1 09:54 Now i need to sum all the days and get the sum as 7 Please suggest that how can i do this task any help will be appreciated

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Elizabeth Rani wrote:

      Now i need to sum all the days and get the sum as 7

      Seems to add up to 6! You can used compute after you query in the proc

      compute sum(Days)

      or put the existing query into another outer query

      Select sum(days) from (put your query here)

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups