copying from one table to another table with existing records

teorge
Member Posts: 1
Hi I'm a beginner in Navision and have a quick question, I want to copy records from OtherTempHeader table to rec but rec might have some records already... So far my code looks like this:
if not IsEmpty then begin
FindLast();
if OtherTempHeader.FindSet() then
repeat
rec := OtherTempHeader;
Insert();
until OtherTempHeader.next() = 0;
end
else begin
if OtherTempHeader.FindSet() then
repeat
rec := OtherTempHeader;
Insert();
until OtherTempHeader.next() = 0;
end;
It doesn't work. I would appreciate any tips, thank you
!
if not IsEmpty then begin
FindLast();
if OtherTempHeader.FindSet() then
repeat
rec := OtherTempHeader;
Insert();
until OtherTempHeader.next() = 0;
end
else begin
if OtherTempHeader.FindSet() then
repeat
rec := OtherTempHeader;
Insert();
until OtherTempHeader.next() = 0;
end;
It doesn't work. I would appreciate any tips, thank you

0
Answers
-
Please define "It doesn't work."
Please use [code] quoting for your code, so indents are preserved. This makes it so much easyer to read, especially if you leave out optional BEGIN ... ENDs
The FINDLAST does not have any effect regarding the inserts - this is a database which uses sorting according to the active key. Duplicates are detected by identical primary keys.
For this reason the entire outer IF is not needed. the inner IFs are identical, You need one of them.
Your code will work as long as you don't have any conflicts.
If you have conflicts, it depends on what you need to do about them. Currently you get an error. (That might be perfectly good behavior.)
If you need to ignore the new duplicate records, tryIF INSERT THEN;
If you need to overwrite duplicate records tryIF NOT INSERT THEN MODIFY;
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions