I think we don't understand eachother correctly. Maybe if I give you some examples we can get a better understanding.

SAMPLE DATA (registered time for 1 user on one day, rownumbers added for clarification):

1....ali sever....01-01-2013 13:00

2....ali sever....01-01-2013 18:30

3....ali sever....01-01-2013 15:30

4....ali sever....01-01-2013 07:30

5....ali sever....01-01-2013 08:30

6....ali sever....01-01-2013 19:30

If you order the above data on registered time, the sequence will be: 4, 5, 1, 3, 2, 6. Therefor I would say rows 4, 1 and 2 will be login times and 5, 3 and 6 will be logout times. When there is an odd number of rows, the last logout is not registered.

According to your assumtion "1-) if user vdate_time <= 09:00 then set log_in time '09:00'" the time of rows 4 and 5 will be altered to 09:00 hours. Your assumption "1-) if user vdate_time <= 18:00 then set log_out time '18:00'" will alter the time of rows 1, 3, 4 and 5 to 18:00, but I think you mean only to alter rows 1 and 3.

With the above sample data: what will be the time that needs to be calculated?

Option 1: Is it the time between 4 and 5 plus the time between 1 and 3 plus the time between 2 and 6 => 60+150+60=270 minutes ?

Option 2: Is it the time between 4 (earliest) and 6 (latest) => difference between 07:30 and 19:30 => 720 minutes ?

Option 3: Is it the time of row 4 changed to 09:00 and row 6 (latest) => difference between 09:00 and 19:30 => 630 minutes ?

Or is it something else?

The code in my post above is calculating the time according to the third option.

First of all thank you for your wonderful help.

I'll try to explain one by one.

Lets talk about your wonderful example

SAMPLE DATA (registered time for 1 user on one day, rownumbers added for clarification):

1....ali sever....01-01-2013 13:00

2....ali sever....01-01-2013 18:30

3....ali sever....01-01-2013 15:30

4....ali sever....01-01-2013 07:30

5....ali sever....01-01-2013 08:30

6....ali sever....01-01-2013 19:30

Firstly we'll have only one log_in time and only one log_out time for 1 day. Discard other 4 records,we'll chosee 2 records from 1,2,3,4,5,6. one log_in time and one log_out time

there are 2 rules in log_in time:

1-) When we look example our code will should be set log_in time = 09:00 because user log_in before 09:00 I dont want before,it's not important we'll set 09:00 if user came early.İf user come before 09:00 users log_in time will be 09:00 (we can control it with ıf or case statement ı donot know)

2-) İf user came after 09:00 we'll use registered time,there is not any modification.So log_in time will be register time.

If we look table ....ali sever....01-01-2013 log_in time will be 01-01-2013 09:00 (not 07:30,not 08:30)

After we decided log_in time then we'll decide log_out time

there are also 2 rules in log_out time:

a-) if user register time > 18:00 we'll use registered time,there is not any modification.

b-) if user register time 14:00 < registered_time < 18:00 We'll update log_out time 18:00,we'll change it with 18:00,we set log_out time 18:00

If we look table ....ali sever....01-01-2013 log_out time will be 01-01-2013 19:30 (not 18:00,not 18:30 not15:30 ..)

for example if user have like this records

1....serap genc....01-01-2013 09:30

2....serap genc....01-01-2013 09:50

3....serap genc....01-01-2013 17:45

3....serap genc....01-01-2013 17:55

serap genc log_in time = 01-01-2013 09:30 because user doesnot have any record which before 09:00(look log_in time rule 2)

serap genc log_out time = 01-01-2013 18:00 because user 14:00 < log_out < 18:00 ( look at log_out rule b)

Lastly I want to see total work time .(log_out - log_in)

like this

FULLNAME ---------LOG_IN--------------- LOG_OUT--------------------- WORKINGHOUR

....ali sever........01-01-2013 09:00 ------01-01-2013 19:30 --------------LOG_OUT - LOG_İN = MİN.

....serap genc.... 01-01-2013 09:30----- 01-01-2013 18:00 ---------------LOG_OUT - LOG_İN = MİN

.

.

.

.CONTUNİE FOR ABOUT 50 USER...

Thank you now your best help , its to important for me