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
 Appending Table to same structured table

Author  Topic 

gsrinivas.
Yak Posting Veteran

56 Posts

Posted - 2008-10-25 : 03:42:07
hi,
How can i append a table to another same structured table.
(for example,
create table numbers(i int)
go
insert numbers (i) values(1)
insert numbers (i) values(2)
insert numbers (i) values(3)
insert numbers (i) values(4)
go
select * from numbers
Now i want to create another table with same structure..
create table numbers2(i int)
go
insert numbers2 (i) values(5)
insert numbers2 (i) values(6)
insert numbers2 (i) values(7)
insert numbers2 (i) values(8)
go
select * from numbers2
========================================

now my requirement is appending (numbers2) table to (numbers) table

after executing the required query ,the numbers (first table) table
contains numbers from 1 to 8

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-25 : 03:53:58
insert into numbers
select * from numbers2
Go to Top of Page

malaytech2008
Yak Posting Veteran

95 Posts

Posted - 2008-10-25 : 04:23:19
select * into numbers from numbers2

malay
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-25 : 04:26:20
quote:
Originally posted by malaytech2008

select * into numbers from numbers2

malay


nope. this will throw error as table already exists. The reqmnt is 'append to an already existing table'
Go to Top of Page

gsrinivas.
Yak Posting Veteran

56 Posts

Posted - 2008-10-25 : 08:13:58
is it working..
select * into numbers from numbers2

i think the error message may be occurs...
"numbers" already existed....

okok... i can check it at home..
thanks for reply...
Go to Top of Page

gsrinivas.
Yak Posting Veteran

56 Posts

Posted - 2008-10-25 : 08:14:24
is it working..
select * into numbers from numbers2

i think the error message may be occurs...
"numbers" already existed....

okok... i can check it at home..
thanks for reply...
Go to Top of Page

malaytech2008
Yak Posting Veteran

95 Posts

Posted - 2008-10-25 : 08:45:19
thanks to u..
mistakes in recognizing tables ->>
correct one
select * into numbers2 from numbers

malay
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-25 : 09:14:01
quote:
Originally posted by malaytech2008

thanks to u..
mistakes in recognizing tables ->>
correct one
select * into numbers2 from numbers

malay


you missed my point. what i told was as numbers2 already exists it will throw error. If you look at OPs post what it suggests is he has two tables table1 (with rows 1 to 4) and table2(with rows 5 to 8) and reqmnt was to append records of table2 to table1 so that it contains records 1-8. Your query tries to create numbers2 table which already exists that why error. for appending numbers2 to numbers what you should be doing is
insert into numbers
select * from numbers2

which add rows 5-8 to numbers table so that it will contain 1-8 rows.
Go to Top of Page

gsrinivas.
Yak Posting Veteran

56 Posts

Posted - 2008-10-26 : 04:02:57
hai visakh!
thank you for reply.

its working fine .
actually my idea is same as yours.
but what wrong is...
insert into first_table values select * from second_table.
_______________________-------____________________________

yaya.. my misatke is just "values"


any how thank you.
and i will post another doubt.

Go to Top of Page

malaytech2008
Yak Posting Veteran

95 Posts

Posted - 2008-10-26 : 06:00:42
thanks visakh.

malay
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-26 : 06:57:01
quote:
Originally posted by gsrinivas.

hai visakh!
thank you for reply.

its working fine .
actually my idea is same as yours.
but what wrong is...
insert into first_table values select * from second_table.
_______________________-------____________________________

yaya.. my misatke is just "values"


any how thank you.
and i will post another doubt.




no worries
you're welcome
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-26 : 06:59:38
quote:
Originally posted by malaytech2008

thanks visakh.

malay


welcome
Go to Top of Page
   

- Advertisement -