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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select Into problem

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?

Thankyou

SELECT coursename, coursedescription
INTO ptcourses08 (coursetitle,coursedescription)
FROM webcourses08

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-07-14 : 07:40:12
SELECT coursename as 'coursetitle', coursedescription
INTO ptcourses08
FROM webcourses08

Jim
Go to Top of Page

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?

Thankyou

SELECT coursename, coursedescription
INTO ptcourses08 (coursetitle,coursedescription)
FROM webcourses08



Are you doing this for one timw?
Go to Top of Page

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
Go to Top of Page

mattastic
Starting Member

15 Posts

Posted - 2008-07-14 : 08:40:14
quote:
Originally posted by jimf

SELECT coursename as 'coursetitle', coursedescription
INTO ptcourses08
FROM webcourses08

Jim




Thanks for your reply, I get this error with your code:

There is already an object named 'ptcourses08' in the database.
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-07-14 : 08:41:00
If the table already exists

INSERT INTO ptcourses08
SELECT coursename, coursedescription
FROM webcourses08
Go to Top of Page

mattastic
Starting Member

15 Posts

Posted - 2008-07-14 : 08:44:18
Works great thankyou!
Go to Top of Page

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', coursedescription
INTO ptcourses08
FROM webcourses08

Jim




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.
Go to Top of Page
   

- Advertisement -