UPDATE multiple rows

  • I am working on an SSIS package that uses sp_MSforeachdb to run sp_helprotect and load it into a table for auditing. As it goes through each database, I need to populate the database name before moving to the next, but not overwrite the existing database names.

    Here is the sequence:

    USE database_1

    EXEC sp_helprotect - adds new records (database_name is NULL for these)

    UPDATE the database_name if it is NULL

    USE database_2......etc

    Here is what I want to do, but this cannot handle multiple rows:

    IF (SELECT database_name FROM Table) IS NULL

    UPDATE Table

    SET database_name = db_name()

    Thanks for the help!

  • You can use a WHERE clause with an UPDATE statement in T-SQL.

    UPDATE Table

    SET database_name = db_name()

    WHERE database_name IS NULL

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills

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

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