给包含compid列且值为null ,表的行数据赋值--


IF OBJECT_ID ('dbo.spSelectColValue_In_DB') IS NOT NULL
DROP PROCEDURE dbo.spSelectColValue_In_DB
go
create proc spSelectColValue_In_DB
AS
DECLARE @tableName varchar(50)
DECLARE My_Cursor CURSOR
FOR (select OBJECT_NAME(id) from syscolumns where id in(
select id from sysobjects where type='U')
and LOWER(name)='compid')
OPEN My_Cursor;
FETCH NEXT FROM My_Cursor INTO @tableName;
WHILE @@FETCH_STATUS = 0
BEGIN
declare @sql nvarchar(1000)
set @sql=' update '+@tableName +' set COMPID=(select top 1 id from Comp_Company) where COMPID is null'
print @sql
exec (@sql)
FETCH NEXT FROM My_Cursor INTO @tableName;
END
CLOSE My_Cursor;
DEALLOCATE My_Cursor;
GO
exec spSelectColValue_In_DB

GO

posted @ 2016-01-15 12:00  Mark1997  阅读(292)  评论(0编辑  收藏  举报