具有可变列名的动态更新语句

编程入门 行业动态 更新时间:2024-10-10 06:22:13
本文介绍了具有可变列名的动态更新语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们希望在多个 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;

更多推荐

具有可变列名的动态更新语句

本文发布于:2023-07-22 00:47:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1182540.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   动态

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!