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
 Transact-SQL (2005)
 Gettting multiple rows into 1 row grouped by

Author  Topic 

vijayakumar_svk
Yak Posting Veteran

50 Posts

Posted - 2007-06-07 : 12:59:37
Can anyone convert the following query into SQL server 2005

SELECT deptno
, LTRIM(MAX(SYS_CONNECT_BY_PATH(ename,','))
KEEP (DENSE_RANK LAST ORDER BY curr),',') AS concatenated
FROM ( SELECT deptno
, ename
, ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) AS curr
, ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) -1 AS prev
FROM emp )
GROUP BY deptno
CONNECT BY prev = PRIOR curr AND deptno = PRIOR deptno
START WITH curr = 1;

Thank in advance
VJ

==============================
Work smarter not harder take control of your life be a super achiever

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-08 : 10:43:13
You need to follow this logic
http://www.nigelrivett.net/RetrieveTreeHierarchy.html


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -