我们希望在多个 SQL Server 数据库中进行更新,以将某个表中的所有 NULL 值更改为空字符串而不是 NULL.我们可能会在数百个数据库中执行此操作.表名将始终相同,但列名根据前端应用程序的配置方式是可变的(不要判断......我没有创建这个系统).
We're looking to do an update in several SQL Server databases to change all NULL values in a certain table to be empty strings instead of NULL. We're potentially going to be doing this across hundreds of databases. The table name will always be the same, but the column names are variable based on how the front-end application is configured (don't judge... I didn't create this system).
有没有办法在不提前知道列名的情况下对所有这些列进行更新?
Is there a way to do an update on all of these columns without knowing the column names ahead of time?
推荐答案动态sql中可以传入列名:
You can pass the name of the column in dynamic sql:
declare @sql nvarchar (1000); set @sql = N'update table set ' + @column_name + '= '''''; exec sp_executesql @sql;更多推荐
具有可变列名的动态更新语句
发布评论