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)
 append data into different table

Author  Topic 

dbonneau
Yak Posting Veteran

50 Posts

Posted - 2009-02-25 : 11:53:27
Hi,

I would like to get some data from table A and append it into table B which has exactly same fields.
I used following logic but gives me an error saying "Incorrect syntax near the keyword into"

select * from table A
into table B
where contractname = 'F' and date = '02/19/2009'

Thanks



vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-02-25 : 11:55:01
It shud be

select * into table B from table A
where contractname = 'F' and date = '02/19/2009'
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-25 : 11:55:15
Use :

Insert into Tablename
Select query........
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-25 : 11:55:59
quote:
Originally posted by vijayisonly

It shud be

select * into table B from table A
where contractname = 'F' and date = '02/19/2009'




This won't work as table is already created.
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-02-25 : 14:12:20
Oh yeah...sorry abt that Sodeep...

SELECT INTO cannot be used on an existing table.
Go to Top of Page

dbonneau
Yak Posting Veteran

50 Posts

Posted - 2009-04-15 : 13:51:28
quote:
Originally posted by sodeep

Use :

Insert into Tablename
Select query........




Hi,
I created a new table and tried to insert data from existing table. But I am getting an error on insert into part
my tableAAA has all fields except [ID], [DIff] and [Flag]
Does anyone know how to fix this problem ?

Thank you so much !

Create Table [dbo].[tablenew] (
[ID] int identity(1,1) not null,
[Date] datetime null,
[Time] datetime null,
[Volume] int null,
[Price] float null,
[Diff] float null,
[Flag] nchar(1) null
)

insert into tablenew from tableAAA








\
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-04-15 : 13:53:56
[code]
insert into tablenew ([Date],[Time],[Price])
SELECT [Date],[Time],[Price] from tableAAA
[/code]
Go to Top of Page

dbonneau
Yak Posting Veteran

50 Posts

Posted - 2009-04-15 : 14:08:01
quote:
Originally posted by visakh16


insert into tablenew ([Date],[Time],[Price])
SELECT [Date],[Time],[Price] from tableAAA




Thank you so much !!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-04-15 : 14:14:13
welcome
Go to Top of Page
   

- Advertisement -