Solved

sql insert question

Posted on 2001-06-08
8
203 Views
Last Modified: 2010-04-06
I need to insert some table (padronf) with all it's records and fields into another table (padron) which has the same records (I mean the same names) plus one which is autonumber. So to be short, I need the SQL statement to insert all the records in padronf into padron and generate the correct autonumbers for IdAfi.
I know this is done with the INSERT keyword but don't know the correct sintax.

So, do you know how to do this? I suppose you do, so please help me.

thanks.
0
Comment
Question by:pin_plunder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 8

Expert Comment

by:Cesario
ID: 6168426
Hi,


try this statments ;-)

MERGE SELECT * FROM padron
  WITH SELECT * FROM padronf

Regrads

Cesario
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6168539
Insert into padron (FieldList_AutoincField_Excluded) Select (FieldList_AutoincField_Excluded) from padronf
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6168557
sorry, should be

Insert into padron (FieldList_AutoincField_Excluded) Select FieldList_AutoincField_Excluded from padronf

;-)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:pin_plunder
ID: 6171095
Cesario: I get the error 'Invalid use of the given token: MERGE'.

kretch..: there are 20 fields, I won't write all there names twice. And, I must say I tried to do so, but not  autonumber is 'created'.

thanks.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6171265
>but not  autonumber is 'created'.

is this number for the autonumberfield not provided by your databasesystem?
what databasesystem do you use?
0
 

Author Comment

by:pin_plunder
ID: 6171775
sorry, just corrected that. However, my question now is the following: is there any way to avoid duplicate records. Supose I run the sql command with the insert statement. Now I do this again. So, those records will be twice in padron.db.

can I avoid this?

thanks.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6172885
well

insert into padron select * from padronf where autonumberfield not in (select autonumberfield from padron)
0
 
LVL 2

Accepted Solution

by:
Felixin earned 50 total points
ID: 6248966
Did you try

Insert into padron (FieldList_AutoincField_Excluded) Select DISTINCT FieldList_AutoincField_Excluded from padronf

?

Felixin

Pimientos del Padron : unos pican y otros no
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question