CREATE TABLE A
(
ID INT IDENTITY( 1,1 ) NOT NULL PRIMARY KEY CLUSTERED
, Column1 INT NULL
, Column2 INT NULL
, Column3 INT NULL
)
CREATE TABLE TEXT
(
ID INT IDENTITY( 1,1 ) NOT NULL PRIMARY KEY CLUSTERED
, [Column] INT NULL
)
INSERT INTO A ( Column1, Column2, Column3 )
SELECT 1, 2, 3
INSERT INTO A ( Column1, Column2, Column3 )
SELECT 4, 5, 6
INSERT INTO A ( Column1, Column2, Column3 )
SELECT 7, 8, 9
select ID, Column1, Column2, Column3
from A
select ID, [Column]
FROM [TEXT]
INSERT INTO TEXT( [Column] )
SELECT TEXTID
FROM
(SELECT ID, Column1, Column2, Column3
FROM A) Tmp
UNPIVOT
(TEXTID FOR A IN
(Column1 , Column2, Column3 )
)AS unpvt