Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Every One,

I am working in asp.net application. In which I have a requirement to show records from three tables.
following are my tables

table1: employee
column names: ID, Name, EmailID

table2: project
column names: ID, Date, EmpID, ProjectName

table3: Detail
column names: ID, Date, EmpID, SpentTime, Desc

Now my requirement is that i want following columns from three table using joining

Date, EmpID, ProjectName, Sum(SpentTime)

In these tables for a single date in project table multiple records may be exists. I am not able to getting the records with sum of time when i am retrieving records for a month then it is not returning the sum of single date time instead it returns the sum of time for a full moth.

so please give me SQL query which can help me.
Posted
Comments
E.F. Nijboer 24-Jul-12 8:27am    
Someone could just give you some answer (which hopefully does the job, because you can't determine it due to lack of knowledge and/or interest) or you could go look on the internet or open a book and do some learning. Try something yourself and if there is a problem you can ask about that.
[no name] 24-Jul-12 9:10am    
On top of that, your requirement does not make any sense. "the sum of single date time", think about that for a minute and figure out what that means.... what is the sum of 1 for instance.
snorkie 24-Jul-12 10:18am    
Post the SQL you have tried and I'll help you get it straightened out.

1 solution

Try this ..
SQL
SELECT SUM(SpentTime - CAST('0:0:0' as TIME))
  FROM YourTableName
 
Share this answer
 
Comments
coolnavjot31 25-Jul-12 1:53am    
Hello I am using following Sql query :

select e.ID, e.Name, e.EmailID, p.Date, p.ProjectName, d.Desc, Sum(d.SpentTime) as SpentTime from employee as e inner join project as p on e.ID = p.EmpID
Join Detail as d on e.ID = d.EmpID where e.ID = 1002 and Month(p.Date) = 7 group by p.Date, e.ID, e.Name, e.EmailID, p.ProjectName, d.Desc
archies_gall 25-Jul-12 11:29am    
Did you try this?

select e.ID, e.Name, e.EmailID, p.Date, p.ProjectName, d.Desc, Sum(d.SpentTime - CAST('0:0:0' as TIME)) as SpentTime from employee as e inner join project as p on e.ID = p.EmpID
Join Detail as d on e.ID = d.EmpID where e.ID = 1002 and Month(p.Date) = 7 group by p.Date, e.ID, e.Name, e.EmailID, p.ProjectName, d.Desc
archies_gall 25-Jul-12 11:34am    
What data you have in the SpentTime column?
Can you give me example data in your table?
coolnavjot31 26-Jul-12 2:31am    
In My SpentTime Column i have time in minutes(Data type- integer).
archies_gall 26-Jul-12 5:43am    
In minutes??
that means u have only data as
SpentTime
----------
45
30
25
59

like this only right?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900