dynamic t-sql update or insert statement

  • is there a better way to write this statement:

    DECLARE @xxx as mvarchar

    if (select col from table where col=@xxx) is not null

    update table statement

    else

    insert table statement

  • I personally would use:

    If Exists (Select Col from Table where Col = @xxx)

    Update

    Else

    Insert

  • Agree EXISTS is supposedly to be faster!

    I just return '1' versus (* or a column).

    If Exists (Select '1' from Table where Col = @xxx)

    Update

    Else

    Insert

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply