stored procedure update

  • There is a stored procedure that updates some columns. I want the following:

    if the column value already exists it must not run update.

    How can this be done?

  • UPDATE t1
    SET t1.col1 = ISNULL(t1.col1,UpdateValue)

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Not much to go on, but, in general, just put the appropriate conditions in the WHERE clause:

    DECLARE @key_value ...
    DECLARE @col_value ...

    SET @key_value = ...
    SET @col_value = ...

    UPDATE dbo.table_name
    SET nonkey_col = @value1
    WHERE key_col1 = 'key_value' AND (nonkey_col IS NULL OR nonkey_col <> @col_value)

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.

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

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