June 16, 2005 at 2:04 am
Hello Friends,
Please Help Me Out!!
Note: Employee ID is Primary Key | ||
Department ID | Employee Name | Employee ID |
101 | Mack | A1001 |
101 | Krish | A1003 |
101 | Harsh | A1004 |
101 | Marry | A1008 |
103 | Susam | A1016 |
103 | Mohan | A1021 |
103 | Gayle | A1033 |
104 | King | A1000 |
105 | Potter | A1005 |
105 | Hussain | A1006 |
Here My Table And I want Output like below
Department ID | Employee Name | Employee ID |
101 | Mack | A1001 |
Krish | A1003 | |
Harsh | A1004 | |
Marry | A1008 | |
103 | Susam | A1016 |
Mohan | A1021 | |
Gayle | A1033 | |
104 | King | A1000 |
105 | Potter | A1005 |
Hussain | A1006 |
Can Anybody have solution for this?
T I A
Shashank
Regards,
Papillon
June 17, 2005 at 2:32 am
Something like:
SELECT
CASE WHEN [Employee ID] = (SELECT MIN([Employee ID]) FROM emp e
WHERE e.[Department ID] = emp.[Department ID])
THEN CAST([Department ID] AS varchar(10))
ELSE ''
END AS [Department],
[Employee Name],
[Employee ID]
from emp
ORDER BY [Department ID], [Employee ID]
Important that you call the first field something other than [Department ID],
so it can sort by the original department ID field. The first field gets cast to
a string so you can send a blank rather than just a NULL if it was an integer.
June 17, 2005 at 3:16 am
Hello friends!!!!!
The solution which Tony Webster has given that worked out!!!!
Thanks Tony!!!!
Shashank
Regards,
Papillon
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply