SQL Server Performance

IF EXISTS functionality with a scope Identity thrown in

Discussion in 'Getting Started' started by dfairchild, Jan 30, 2014.

  1. dfairchild New Member

    I have done a few IF EXISTS statements before but never one with the added twist of reutrning back a newly created id if not. Here is what I am trying to do...
    I bring data in to a table (table1) that contains an email address (email_addr). I need to compare this column to the email addresses I already have in my email address table (table2) with the same column name. If they exist, I need to send the email_id (incrementing column in table2) back from table2 and update the email_id in table1. If they do not exist in table2, I need to insert them in table2 and send back the newly created email_id to update table1.
    Can you help? It would be greatly appreciated.

Share This Page