Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
uhertz
Starting Member
2 Posts |
Posted - 2011-12-13 : 02:51:01
|
| HiI have a 3 column SQL table, T1: column name is ID structure is int, and column name "REASON" varchar(50) I want to create a second table, T2 where column 1 is the reason column from T1 and column2 is a new column with a unique primary key and column 3 is the ID column from T1. How do I do this? Can I use a while loop, ie create the table and then insert the rows? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-13 : 03:58:33
|
you just need thisSELECT Reason AS Column1,IDENTITY(int,1,1) AS Column2,ID AS Column3INTO T2FROM T1 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-12-15 : 03:41:36
|
| Why do you want to create a new table for this? You can just create a view instead with this codecreate view view_nameasselect reason, row_number() over (order by reason) as sno from tableMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|