简体   繁体   English

SQL Server - 在不知道列的情况下更新表只是值

[英]SQL Server - Update table without knowing the column just the value

Hope someone will help me with my problem ...希望有人能帮我解决我的问题...

How can I update my table with this: I have the value eg.我怎样才能用这个更新我的表:我有价值,例如。 ' April 28, 2017 ' ' April 28, 2017 '

And I need to find the column containing that value.我需要找到包含该值的列。

My columns looks like this:我的列看起来像这样:

train_date | train_date1 | train_date2 | train_date3 | train_date4 | train_date5 | train_date6

Then the table(s) contained that value will be updated to NULL .然后包含该值的表将更新为NULL

Thanks.谢谢。

Do you mean to update column containing particular value to NULL ?您的意思是将包含特定值的列更新为NULL吗? Then you can use CASE condition to check if column contains that value then update it to NULL else leave it as it is.然后您可以使用CASE条件来检查列是否包含该值,然后将其更新为NULL,否则保持原样。

UPDATE traintable
SET train_date = CASE WHEN train_date  = 'April 28, 2017' THEN NULL ELSE train_date  END,
train_date1 = CASE WHEN train_date1  = 'April 28, 2017' THEN NULL ELSE train_date1  END,
train_date2 = CASE WHEN train_date2  = 'April 28, 2017' THEN NULL ELSE train_date2  END,
train_date3 = CASE WHEN train_date3  = 'April 28, 2017' THEN NULL ELSE train_date3  END,
train_date4 = CASE WHEN train_date4  = 'April 28, 2017' THEN NULL ELSE train_date4  END,
train_date5 = CASE WHEN train_date5  = 'April 28, 2017' THEN NULL ELSE train_date5  END,
train_date6 = CASE WHEN train_date6  = 'April 28, 2017' THEN NULL ELSE train_date6  END

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不知道列名的情况下获取列值? SQL服务器 - How to get Column value without knowing column name ? SQL Server 在不知道SQL Server数据库中的表或列名称的情况下查找单元格值的位置 - Find location of a cell's value without knowing table or column name in a sql server database SQL Server在不知道列名的情况下从表中选择数据 - SQL Server Select data from table without knowing column names 可以在不知道结果列名的情况下进行 SQL Server Pivot 吗? - Can SQL Server Pivot without knowing the resulting column names? SQL Server:删除表主键,但不知道其名称 - SQL Server: drop table primary key, without knowing its name 如何在SQL Server中更新表并添加列值? - How to update table and add column value in SQL Server? SQL Server更新列基于另一个表中的值 - SQL Server Update Column based on value from another table SQL Server:根据同一表中另一列与另一表的列的匹配值,更新一个表中的列的值 - SQL Server: update value of a column in one table based on the matching value of another column in the same table to another table's column 如何在没有聚集且不知道列值的情况下使用SQL PIVOT表? - How do I use SQL to PIVOT a table without an aggregate and without knowing column values? 在SQL Server中对动态列重新编号而不进行更新 - Renumber dynamic column without update in SQL Server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM