Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to create Total time, count it

Author  Topic 

jeffliew
Starting Member

6 Posts

Posted - 2005-08-29 : 02:01:59
i hv a problem in sql,

i) if in data hv time_start, time_end, date , id, how i can calculate the total time for very sesion user login

ii) how to make it if the total come out hv same id(may be two id hv two diffrent total), i want make it just one id then the total time...

post me at jeffliew2001@yahoo.com

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-29 : 02:27:04
Post table structure, some sample data and the result you want

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

kapilarya
Yak Posting Veteran

86 Posts

Posted - 2005-08-29 : 02:54:31
quote:
Originally posted by jeffliew

i hv a problem in sql,

i) if in data hv time_start, time_end, date , id, how i can calculate the total time for very sesion user login

for this you can do the
DATEDIFF ( datepart , startdate , enddate )

ii) how to make it if the total come out hv same id(may be two id hv two diffrent total), i want make it just one id then the total time...
Post data and table structure
post me at jeffliew2001@yahoo.com



Kapil Arya
Go to Top of Page

jeffliew
Starting Member

6 Posts

Posted - 2005-08-29 : 11:57:54
This is the table struture

Student_ID , Hostname, IP_Adress, Time_Start , Time_End, Date ,Total_Time

sample data
Student_id Hostname IP_Adress TimeStart Time_end Date Total_Tim
B030210245, pc2, 12.5.8.9, 4.00pm, 6.00pm, 8/21/2005, 2Hours
B030210246, computer, 12.1.1.1, 11.00am, 4.00pm , 8/22/2005, 5Hours
B030210246, pc1, 12.1.1.4, 8.00am, 12.30pm , 8/22/2005,4.30Hours

so in the following i give it, i wan to know how to get the total_time, after this i wan make ID B030210246 to be one line like example:

Student_id Totaltime
B030210246 9.30Hours
Go to Top of Page

jeffliew
Starting Member

6 Posts

Posted - 2005-08-29 : 12:02:22
This is the table struture

Student_ID , Hostname, IP_Adress, Time_Start , Time_End, Date ,Total_Time

sample data
Student_id Hostname IP_Adress TimeStart Time_end Date Total_Tim
B030210245, pc2, 12.5.8.9, 4.00pm, 6.00pm, 8/21/2005, 2Hours
B030210246, computer, 12.1.1.1, 11.00am, 4.00pm , 8/22/2005, 5Hours
B030210246, pc1, 12.1.1.4, 8.00am, 12.30pm , 8/22/2005,4.30Hours

so in the following i give it, i wan to know how to get the total_time, after this i wan make ID B030210246 to be one line like example:

Student_id Totaltime
B030210246 9.30Hours
Go to Top of Page

jeffliew
Starting Member

6 Posts

Posted - 2005-08-29 : 12:03:19
This is the table struture

Student_ID , Hostname, IP_Adress, Time_Start , Time_End, Date ,Total_Time

sample data
Student_id Hostname IP_Adress TimeStart Time_end Date Total_Tim
B030210245, pc2, 12.5.8.9, 4.00pm, 6.00pm, 8/21/2005, 2Hours
B030210246, computer, 12.1.1.1, 11.00am, 4.00pm , 8/22/2005, 5Hours
B030210246, pc1, 12.1.1.4, 8.00am, 12.30pm , 8/22/2005,4.30Hours

so in the following i give it, i wan to know how to get the total_time, after this i wan make ID B030210246 to be one line like example:

Student_id Totaltime
B030210246 9.30Hours
Go to Top of Page

JimL
SQL Slinging Yak Ranger

1537 Posts

Posted - 2005-08-29 : 14:50:01
1st problem is that your useing time_start, time_end, date

what happens when it runs through 11:59 PM?

Time_start and Time_end should be in full datetime format this will allow you to use date diff.

Jim
Users <> Logic
Go to Top of Page
   

- Advertisement -