Solved

sql insert question

Posted on 2001-06-08
8
201 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
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
Help on project with Soap 10 57
PHP preg_replace code convert to Delphi 14 67
RESTRequest Parameter 4 43
Twebbrowser in Fire monkey android scrolling to bottom 1 45
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…

861 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