with x (deptno, cnt, list, empno, len)
as (
as (
select deptno
, count(*) over (partition by deptno)
, cast(ename as varchar(100))
, empno
, 1
union all
select x.deptno, x.cnt, x.list ',' e.ename, e.empno, x.len+1
from emp e, x --> recursive call
where e.deptno = x.deptno and e.empno > x. empno
)
select deptno,list
from x
where len = cnt ;
from emp
union all
select x.deptno, x.cnt, x.list ',' e.ename, e.empno, x.len+1
from emp e, x --> recursive call
where e.deptno = x.deptno and e.empno > x. empno
)
select deptno,list
from x
where len = cnt ;
'MS-SQL' 카테고리의 다른 글
| SSMS에서 쿼리 실행 후 한글 입력으로 자동 변경되는 경우 (0) | 2014.04.21 |
|---|---|
| Single User 모드로 서비스 시작 (0) | 2011.10.19 |
| Database 복구 후 로그인과 사용자 매핑 (0) | 2011.10.19 |
| SET XACT_ABORT ON (0) | 2011.07.13 |
| openquery에서 7347 에러 발생 (0) | 2011.07.11 |
| DMV (Dynamic Management Views) (0) | 2010.08.06 |
| SQL Server 2008 Database Mail 셋팅 (0) | 2010.01.21 |
| 데이터베이스 소유자 변경 (0) | 2010.01.12 |
| SQL Server Instance 접속 시 Dynamic Port 대신 고정 Port로 셋팅 (0) | 2010.01.11 |
| Error 21002 [SQL-DMO] user already exists 오류 발생 시 (0) | 2010.01.08 |

