우욱님이 먼저 답변 해주신거 감사 드립니다..
지금 열심히 스터디 중입니다..^^;;
저번에 답변 해주신거에서요..
CREATE TABLE #tt (
PLANT NVARCHAR(20)
, GOO NVARCHAR(20)
, M3 NVARCHAR(20)
, [DATE] NVARCHAR(20)
)
INSERT INTO #tt
SELECT N'광주공장', N'GHDIC110', N'10000', N'2013-06-14'
UNION ALL SELECT N'수원공장', N'GHDIC111', N'8000', N'2013-06-14'
UNION ALL SELECT N'천안공장', N'GHDIC112', N'7000', N'2013-06-14'
SELECT dd FROM
(SELECT * FROM
(SELECT TOP(SELECT COUNT(*) FROM #tt) ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS rn FROM sys.all_columns) AS kk
CROSS JOIN
(
SELECT 1 AS sn, N'재료명' AS dd
UNION ALL SELECT 2 AS sn, N''
) AS attached
UNION ALL
SELECT ROW_NUMBER() OVER( ORDER BY PLANT ) AS rn, 0 AS sn, N'공장명' FROM #tt) AS ff
ORDER BY rn , SN
여기에서요 ..... Select문 첫부분 dd,ss,kk,uu 필드를을 추가 해주고 싶은데 아무리 마추고,응용해도 자꾸 컬럼 갯수가 안맞다고 오류 뜨는데요..
필드별로 만들고 싶습니다..
현재는 dd 필드만 존재 하는데요..
만약에요
select dd , ss , kk , uu <---- 이런 식으로 필드를 추가 하고요...
dd:공장명
ss:실데이터값(공장명)
kk:제품명
uu:실데이터값(제품명)
뭐가 잘못 되었는지 한번만 더 체크 부탁 드립니다.^^;
예전에 답변해주신 쿼리는....
CREATE TABLE #tt (
PLANT NVARCHAR(20)
, GOO NVARCHAR(20)
, M3 NVARCHAR(20)
, [DATE] NVARCHAR(20)
)
INSERT INTO #tt
SELECT N'광주공장', N'GHDIC110', N'10000', N'2013-06-14'
UNION ALL SELECT N'수원공장', N'GHDIC111', N'8000', N'2013-06-14'
UNION ALL SELECT N'천안공장', N'GHDIC112', N'7000', N'2013-06-14'
SELECT dd FROM
(SELECT * FROM
(SELECT TOP(SELECT COUNT(*) FROM #tt) ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS rn FROM sys.all_columns) AS kk
CROSS JOIN
(
SELECT 1 AS sn, N'원재료명 A1 A2 A3 A4 A5' AS dd
UNION ALL SELECT 2 AS sn, N'설정치 1 2 3 4 5'
UNION ALL SELECT 4 AS sn, N''
) AS attached
UNION ALL
SELECT ROW_NUMBER() OVER( ORDER BY PLANT ) AS rn, 0 AS sn, N'공장명|' + PLANT + N' 제품명|' + GOO + N' 생산량|' + M3 + N' 일자|' + [DATE] FROM #tt) AS ff
ORDER BY rn , SN
|