答案 0 :(得分:0)
对每列使用case
表达式。
select case when column1 = 'X' then 'Column1' else <whatever> end as column1,
case when column2 = 'X' then 'Column2' else <whatever> end as column2,
...
case when column1340 = 'X' then 'Column1340' else <whatever> end as column1340
from tablename
如果你只想要NULL而不是任何东西,你可以跳过else <whatever>
部分。
答案 1 :(得分:0)
对于1,300列,我会去动态SQL
Declare @SQL varchar(max) = ''
Select @SQL = @SQL+coalesce(';Update ['+Table_Name+'] Set ['+Column_Name+']='''+Column_Name+''' where ['+Column_Name+']=''X''' ,'')
From (Select Table_Name,Column_Name From INFORMATION_SCHEMA.COLUMNS where Table_Name='SomeTable') A
Print @SQL
--Exec(@SQL)
返回
;更新[SomeTable]设置[column1] ='column1',其中[column1] ='X';更新[SomeTable]设置[column2] ='column2',其中[column2] ='X';更新[SomeTable]设置[column3] ='column3',其中[column3] ='X'