Insert data from one table to another table
i have on table T1 with data
RK1
RK3
RK5
RK2
i want to insert data in table T2 from T1 with output like
col1 col2
11 RK1
12 RK2
13 RK3
14 RK5
With col2 sorted?
could you please write sql quer开发者_JAVA百科y for the same?
You can do this with an insert:
INSERT INTO YourTable (Col1, Col2)
SELECT 11, RK1
UNION SELECT 12, RK2
UNION SELECT 13, RK3
UNION SELECT 14, RK5
SQL Server 2005 and above
INSERT TABLE2
(col1, col2)
SELECT
'I' + CAST(ROW_NUMBER() OVER (ORDER BY TheCol) AS varchar(10)), TheCol
FROM
TABLE1
ORDER BY
TheCol
精彩评论