Answered Sql server 2005 - sql - insert based on if.

  • יום ראשון 08 ינואר 2012 04:07
     
     

    To whom it may concern,

    Thank you for taking the time to read this and possibly respond.

     

    I wish to be able to check to see if a row exists with certain values and if it doesnt then insert the record.

     

    Im currently trying to avoid 2 connections to the database

    1 to see if the row exists

    2 then insert if necessary

     

    What I wish to do is to be able to do this in a single connection instance to the db

     

    Thanks heaps

כל התגובות

  • יום ראשון 08 ינואר 2012 04:46
     
     תשובה

     

    i think i found something similar to here

     

    http://stackoverflow.com/questions/639854/check-if-a-row-exists-otherwise-insert

     

    thanks anyway

    • סומן כתשובה על-ידי WPHC יום ראשון 08 ינואר 2012 04:46
    •  
  • יום ראשון 08 ינואר 2012 07:29
     
     

     Merge statement is introduced in Sql server 2008, but since you are on SQL Server 2005, you can refer http://sqlserver-tips.blogspot.com/2006/09/mimicking-merge-statement-in-sql.html


    Thanks
    Manish

    Please use Mark as Answer if my post solved your problem and use Vote As Helpful if a post was useful.