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 |
|
mattastic
Starting Member
15 Posts |
Posted - 2008-07-14 : 07:34:26
|
Hi, I'm trying to copy certain columns into a new table, my code is below but it doesnt work, can anyone tell me if this is possible?ThankyouSELECT coursename, coursedescriptionINTO ptcourses08 (coursetitle,coursedescription)FROM webcourses08 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2008-07-14 : 07:40:12
|
| SELECT coursename as 'coursetitle', coursedescriptionINTO ptcourses08 FROM webcourses08Jim |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-14 : 08:19:38
|
quote: Originally posted by mattastic Hi, I'm trying to copy certain columns into a new table, my code is below but it doesnt work, can anyone tell me if this is possible?ThankyouSELECT coursename, coursedescriptionINTO ptcourses08 (coursetitle,coursedescription)FROM webcourses08
Are you doing this for one timw? |
 |
|
|
mattastic
Starting Member
15 Posts |
Posted - 2008-07-14 : 08:26:56
|
| Thanks for your replies. Yes I just need to populate my new table |
 |
|
|
mattastic
Starting Member
15 Posts |
Posted - 2008-07-14 : 08:40:14
|
quote: Originally posted by jimf SELECT coursename as 'coursetitle', coursedescriptionINTO ptcourses08 FROM webcourses08Jim
Thanks for your reply, I get this error with your code:There is already an object named 'ptcourses08' in the database. |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2008-07-14 : 08:41:00
|
| If the table already existsINSERT INTO ptcourses08 SELECT coursename, coursedescription FROM webcourses08 |
 |
|
|
mattastic
Starting Member
15 Posts |
Posted - 2008-07-14 : 08:44:18
|
| Works great thankyou! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-14 : 13:33:01
|
quote: Originally posted by mattastic
quote: Originally posted by jimf SELECT coursename as 'coursetitle', coursedescriptionINTO ptcourses08 FROM webcourses08Jim
Thanks for your reply, I get this error with your code:There is already an object named 'ptcourses08' in the database.
Thats why i asked is it for one time. If you're trying to run in for second time it will again try to create table and will error. Thats why its always better to create table first and then use INSERT..SELECT. |
 |
|
|
|
|
|
|
|