views:

28

answers:

2

Hi,

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 query for the same?

A: 

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
mdma
A: 

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
gbn
Hi,It should be start with 11
Vijay Sharma
please help me on this
Vijay Sharma
@Vijay Sharma: why not try to adapt my solution?
gbn