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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Add Data to existing table

Author  Topic 

nguyenl
Posting Yak Master

128 Posts

Posted - 2008-06-06 : 19:45:20
Hi,

How would I select from TABLE A and add this data to TABLE B which has existing data that I want to keep. I would like to keep adding onto the old data. When I do an "Insert Into", it keeps on deleting my old data.

Thanks,

ganeshkumar08
Posting Yak Master

187 Posts

Posted - 2008-06-07 : 02:39:10
Hello,

The below code will help you, go through it...

declare @Table1 Table(Col1 int,Col2 varchar(100))
insert into @Table1(col1,col2)
select 1, 'sql server' union
select 2, 'oracle' union
select 3, 'DB2' union
select 4, 'my sql' union
select 5, 'ms access'

Declare @Table2 Table(col1 int,col2 varchar(100))
insert into @Table2(col1,col2)
select 1, 'aaaa' union
select 2, 'bbbb' union
select 3, 'cccc' union
select 4, 'dddd' union
select 5, 'eeee'


Select col1,col2 from @Table2

-- Inserting from Table1 to Table2

insert into @Table2
Select col1,col2 from @Table1

select * from @Table2
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-07 : 04:40:38
quote:
Originally posted by nguyenl

Hi,

How would I select from TABLE A and add this data to TABLE B which has existing data that I want to keep. I would like to keep adding onto the old data. When I do an "Insert Into", it keeps on deleting my old data.

Thanks,




Not sure how your old data got deleted when you did insert into. Are you sure you didnt have a truncate/delete statement in batch? Or did you mean select into?
Go to Top of Page
   

- Advertisement -