我想遍历所有表列并替换所有值为“。”的列。在 sql server 中有空值。所以在这里我写了一些逻辑。但不知何故它不起作用。
create table #AllColumns
(
ColNo int not null primary key identity(1,1),
ColumnName varchar(100)
)
insert into #AllColumns
SELECT c.name ColumnName
FROM sys.columns c INNER JOIN
sys.tables t ON c.object_id = t.object_id INNER JOIN
sys.schemas s ON t.schema_id = s.schema_id
where t.name='TabelName'
DECLARE @i int
DECLARE @numrows int
DECLARE @columnName varchar(100)
set @i=1
set @numrows= (SELECT COUNT(*) FROM #AllColumns)
IF @numrows > 0
WHILE (@i <= (SELECT MAX(ColNo) FROM #AllColumns))
BEGIN
set @columnName=(select ColumnName from #AllColumns where ColNo=@i)
update TabelName
set @columnName=null
where @columnName='.'
set @i=@i+1
END
drop table #AllColumns
让我知道我在哪里做错了。