Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2002

    Question Unanswered: UPDATE..... else Insert Record... Is This Possible?

    Hello All SQL Expert.

    I was lead into this forum when I search for solution on the following: -

    Does anyone know how to design a SQL which updates if the WHERE is true, and if not creates a new post?

    I need to find a solution soonest because some sql codes need to be changed urgently. Please help. Greatly appreciated. Thank you.

    I am using SQL 7.

    I could be reached at

    Best regards
    Teck Boon

  2. #2
    Join Date
    Feb 2002
    Houston, TX
    most people will check for the existance of a record ( and possably validate other data) before doing an update. In some cases if the record does NOT exist you can insert a new record id you have enough data.

    if exists(select * from <table in question> where Key = <your search key(s)>)
    update <table in question> set <some field to some value> where key = <your search key(s)>
    insert into <table in question> (<list of attributes>) values(<matching list of values>)

    Hope this helps.
    Paul Young
    (Knowledge is power! Get some!)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts