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
 SQL Server Administration (2005)
 [Ask] Select datetime SQL SERVER 2005

Author  Topic 

madkixt
Starting Member

1 Post

Posted - 2010-03-12 : 03:56:57
Hello My Bro and Guru...

I Newbie Use SQL SERVER 2005 and i have problem to select this Data...

For My Case this example :

I have table=>Absen

| id | Per_Code | Date_Time |
| 1 | 109 | 2009-12-22 07:17:00 |
| 2 | 109 | 2009-12-22 17:17:00 |
| 3 | 109 | 2009-12-23 07:20:00 |
| 4 | 109 | 2009-12-23 18:17:00 |

How I can modify simple SELECT FROM TABLE ABSEN like this ilustration :

| id | Per_Code | Date | Time_In | Time_Out |
| 1 | 109 | 2009-12-22 | 07:17:00 |17:17:00 |
| 2 | 109 | 2009-12-22 | 07:20:00 |18:17:00 |

Please Help Me How i can Solved my case...

Thanks Before...

Contoh image database saya seperti ini :

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-03-12 : 05:27:59
Go by this query....

SELECT ROW_NUMBER() OVER( ORDER BY (SELECT 1) ) ID, per_code, date, Min(Time) Time_In, Max(time) Time_out FROM
(
SELECT Id, per_code, CONVERT(VARCHAR(11), date_time, 103) date, Convert(VARCHAR(20), Date_Time, 108) Time FROM Absen
) a
GROUP BY per_code, date

Vabhav T
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-12 : 12:09:35
you've same date values repeating in your sample data, why is that?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -