Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

sql insert question

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
pin_plunder
Asked:
pin_plunder
1 Solution
 
CesarioCommented:
Hi,


try this statments ;-)

MERGE SELECT * FROM padron
  WITH SELECT * FROM padronf

Regrads

Cesario
0
 
kretzschmarCommented:
Insert into padron (FieldList_AutoincField_Excluded) Select (FieldList_AutoincField_Excluded) from padronf
0
 
kretzschmarCommented:
sorry, should be

Insert into padron (FieldList_AutoincField_Excluded) Select FieldList_AutoincField_Excluded from padronf

;-)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
pin_plunderAuthor Commented:
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
 
kretzschmarCommented:
>but not  autonumber is 'created'.

is this number for the autonumberfield not provided by your databasesystem?
what databasesystem do you use?
0
 
pin_plunderAuthor Commented:
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
 
kretzschmarCommented:
well

insert into padron select * from padronf where autonumberfield not in (select autonumberfield from padron)
0
 
FelixinCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now