Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting with a select * from statement returns Error

Status
Not open for further replies.

bmacbmac

IS-IT--Management
Jan 26, 2006
392
US
Hi,

I am trying to insert data from one DB into another DB with the following statement:

insert into db2..tblparty
select * from db1..tblparty
join tbldocument
on tbldocument.irecordid = tblparty.irecordid
where tbldocument.irecordid between 1 and 1000

I get an error: Insert Error: Column name or number of supplied values does not match table definition.

Although both tables have 9 columns which are set up the exact same.

Is there a way to do this without listing each column individually? I have about 30 tables to insert and each table has a lot of columns.

Thanks,

Brian

 
The code that SQLDenis posted should do the trick. This is the problem with doing a select *.

When you do a select * without specifing the table name before the * (t.* in this example) you are getting all the columns from both tables involved in the join, not just the table in the from statement.

Denny
MCSA (2003) / MCDBA (SQL 2000) / MCTS (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
That worked perfectly. Thanks to you both, you have been a great help to me this year.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top