Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Input :
I am having the table
StaffNo Date Time
12333 12-02-2013 09.30
12333 12-02-2013 17.30

13245 12-02-2013 09.15
13245 12-02-2013 10.10
13245 12-02-2013 17.35

14555 12-02-2013 09.10
14555 12-02-2013 10.40
14555 12-02-2013 11.45
14555 12-02-2013 17.30

Output :

12333 12-02-2013 09.30-17.30
13245 12-02-2013 09.15-10.10,17.35
14555 12-02-2013 09.10-10.40,11.45-17.30

Thanks & Regards,
Nirmal.M
Posted
Comments
Richard C Bishop 19-Feb-13 15:39pm    
You have been a memeber for almost 9 years and you are asking your first question today. What is up with that?
Sergey Alexandrovich Kryukov 9-Apr-13 0:44am    
Excuse me, where did you find a question?!
—SA
Richard C Bishop 9-Apr-13 9:40am    
No question indeed, should have said first thread.

Hi,

try this query,
SQL
SELECT DISTINCT StaffNO, COALESCE(Cast(DateTime As VRACHAR(50)) + '-', '') as 'Time' FROM TableName GROUP BY StaffNo

hope it helps
 
Share this answer
 
see the below query,
might it helps...

SQL
select a.StaffNo,a.Date, SUBSTRING(b.alltime ,1, LEN(b.alltime ) - 1) from 
(select distinct StaffNo, Date from tablename) A cross apply
(select time +',' from tablename where id=a.StaffNo and name=a.Date for xml path('')) B (alltime)
 
Share this answer
 

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