Check if a line exists

sbillysbilly Member Posts: 231
Hi all,
How can I verify if a line exists within a table before inserting it?

Answers

  • GRIZZLYGRIZZLY Member Posts: 127
    How about
    IF NOT TableRec.GET(PrimaryKeyValues) THEN 
      TableRec.INIT;
      TableRec. ... := ...;
      TableRec.INSERT;
    END;
    
    ?
    Sincerely yours, GRIZZLY
    Follow my blog at http://x-dynamics.blogspot.com
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    Don't forget the BEGIN-statement in your example!
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • DenSterDenSter Member Posts: 8,307
    My favorite:
    IF Rec.INSERT THEN;
    
  • SavatageSavatage Member Posts: 7,142
    How do plan on handling it when it does exist?
    Do you want to modify or skip or do something else?
    If it already exists how are going to insert it, you will get an error.
    How about
    If NOT Insert then...
  • David_SingletonDavid_Singleton Member Posts: 5,479
    Savatage wrote:
    How do plan on handling it when it does exist?
    Do you want to modify or skip or do something else?
    If it already exists how are going to insert it, you will get an error.
    How about
    If NOT Insert then...

    I agree with Harry, there are a ton of different ways to do this. YOu need to work out though the business logic of what you are trying to achieve, THEN start thinking of the best code to solve it.

    You have asked what's the best way to get form A to B, but we have no idea where A and B are, A might be your kitchen, and B your bedroom, or A might be the Moon and B might be Mars.
    David Singleton
  • sbillysbilly Member Posts: 231
    GRIZZLY wrote:
    How about
    IF NOT TableRec.GET(PrimaryKeyValues) THEN 
      TableRec.INIT;
      TableRec. ... := ...;
      TableRec.INSERT;
    END;
    
    ?
    It helped me !! Tahnks for all
Sign In or Register to comment.