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
 how do I select into a existing table?

Author  Topic 

kifeda
Posting Yak Master

136 Posts

Posted - 2008-08-26 : 17:46:02
I have a table called tblclients and I have another table called tblclients2. I want copy the a field called f4 from tblclients2 into tblclients. This is what I tried:

select f4 as strinsurancenumber into tblclients from tblclients2

that gives me an error that says the table already exist. What should I do?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-08-26 : 17:47:09
Does the column already exist in tblclients? Are you just trying to update the data? Or do you want a new column with data put into it?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

kifeda
Posting Yak Master

136 Posts

Posted - 2008-08-27 : 13:33:13
the column does not exist
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-27 : 13:40:12
then create it and update

ALTER TABLE tblclients ADD strinsurancenumber varchar(20)


UPDATE t
SET t.strinsurancenumber=t2.f4
FROM tblclients t
INNER JOIN tblclients2 t2
ON t.linkingcol=t2.linkingcol


where linkingcol is the column by which the tables are related
Go to Top of Page

kifeda
Posting Yak Master

136 Posts

Posted - 2008-08-27 : 13:44:25
okay I'll try
Go to Top of Page
   

- Advertisement -