in reply to SQL statment to insert if none exits and to obtain the primary key of a record with one visit!

That's really more of an MSAccess question. I know in Oracle there is a MERGE statement, and (although I forget it now), a way to retrieve the last generated sequence. I'm not sure if there is anything similar in Access, though.
  • Comment on Re: SQL statment to insert if none exits and to obtain the primary key of a record with one visit!

Replies are listed 'Best First'.
Re^2: SQL statment to insert if none exits and to obtain the primary key of a record with one visit!
by jfroebe (Parson) on Jun 16, 2005 at 16:35 UTC

    Agreed. This is not a perl issue at all. The solution lies with how Access works.

    One dbms vendor neutral solution would be to:

    1. begin tran
    2. insert row
    3. if error due to duplicate key, then update if desired.
    4. commit or abort tran

    I mean, there are definitely ways to do this that are vendor neutral, but in some cases the vendor DBMS (MS Access) have better solutions. I don't know about Access other than the basics.

    Jason L. Froebe

    Team Sybase member

    No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

Re^2: SQL statment to insert if none exits and to obtain the primary key of a record with one visit!
by jhourcle (Prior) on Jun 16, 2005 at 21:05 UTC

    Or, for those of us who had to do this sort of thing _before_ Oracle 9i, you had do some nasty things with stored procedures. For instance, when I had to deal with sitescope, it's idea of 'logging to a server' was a 0NF table of varchar2(255) fields. So I had a stored procedure to get things from that table to 3NF, which used a whole bunch of functions like:

    so I could then do:

    (which I triggered from a perl script, that maintained an error log ... therefore this is just barely clinging to being on-topic)