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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to Get Min Login Time & Max Logout Time

Author  Topic 

sanjay5219
Posting Yak Master

240 Posts

Posted - 2009-09-25 : 06:37:54
Dear All,

I am having one table in which i want to know Min Login Time and Max Logout Time and how much hr they have worked.

Please help me it's urgent

Name Lgin Lgot
A 10:34AM 8:00PM
B 10:51AM 3:55PM
B 3:56PM 9:10PM
C 10:58AM 8:00PM
D 7:55AM 7:55AM
E 7:49AM 5:06PM
F 12:43PM 12:52PM
F 12:53PM 2:16PM
F 2:16PM 7:13PM
G 9:57AM 12:43PM

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-25 : 07:03:21
What is the datatype of Lgin and Lgot?

Madhivanan

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

sanjay5219
Posting Yak Master

240 Posts

Posted - 2009-09-25 : 07:06:44
it is nvarchar
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-25 : 07:08:52

select name,min(cast(Lgin as datetime)) as min_time, max(cast(Lgin as datetime)) as max_time from table group by name

Madhivanan

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

Kabila
Starting Member

33 Posts

Posted - 2009-09-25 : 07:11:53
select name,min(lgin),max(lgout),datediff(hh,min(lgin),max(lgout)) from tablename
group by name
Go to Top of Page

sanjay5219
Posting Yak Master

240 Posts

Posted - 2009-09-25 : 07:27:26
great it's working thanks
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-25 : 08:02:35
quote:
Originally posted by sanjay5219

great it's working thanks


Which query is working?

Madhivanan

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

- Advertisement -