set nocount on
    DECLARE @dbname VARCHAR(50)
    DECLARE @t table(id INT IDENTITY(1,1),dbname VARCHAR(50))
    DECLARE @i int,@count INT
    DECLARE @sql nVARCHAR(MAX)
    select @i = 1,@count = 0
    INSERT INTO @t(dbname) SELECT NAME FROM MASTER.DBO.SYSDATABASES where name not in (‘master’,’model’,’msdb’,’tempdb’,’ReportServer’,’ReportServerTempDB’) ORDER BY NAME
    SELECT @count = COUNT(1) FROM @t
    WHILE @i <= @count
    BEGIN
    SELECT @dbname = dbname FROM @t WHERE id = @i
    —PRINT @dbname
    SET @sql = ‘use [‘+@dbname +’]’+ char(13)+char(10)+

    update maintainitem set 维修项目代码= isnull(维修项目代码,’’’’) where 1=0

    begin try
    print @sql
    EXEC (@sql)
    select @dbname as db,’成功’ AS ErrMsg
    end try
    begin catch
    —SELECT ERROR_NUMBER() AS ErrNum,ERROR_SEVERITY()AS ErrSev,ERROR_STATE() AS ErrState,ERROR_PROCEDURE() AS ErrProc,ERROR_LINE()AS ErrLine,ERROR_MESSAGE()AS ErrMsg
    select @dbname as db, ERROR_MESSAGE()AS ErrMsg
    end catch
    SET @i = @i+1
    END
    set nocount off