Click here to Skip to main content
11,637,662 members (76,927 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server
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 18-Feb-13 17:11pm
Comments
richcb at 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 at 9-Apr-13 0:44am
   
Excuse me, where did you find a question?!
—SA
richcb at 9-Apr-13 9:40am
   
No question indeed, should have said first thread.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,

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

hope it helps
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

see the below query,
might it helps...

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)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 jyo.net 380
1 Sergey Alexandrovich Kryukov 309
2 stibee 308
3 OriginalGriff 230
4 sasanka sekhar panda 190
0 OriginalGriff 9,051
1 Sergey Alexandrovich Kryukov 8,773
2 Mika Wendelius 7,034
3 Suvendu Shekhar Giri 2,425
4 F-ES Sitecore 2,408


Advertise | Privacy | Mobile
Web04 | 2.8.150728.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100