如何在SQL Server中使用“替换”更新多个列? [英] How can I update multiple columns with a Replace in SQL server?

查看:111
本文介绍了如何在SQL Server中使用“替换”更新多个列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更新表格中的不同列和行?我想做一些类似于替换字符串的操作在SQL Server中

How do I update different columns and rows across a table? I want to do something similiar to replace a string in SQL server

我想这样做,但是值存在于同一类型的多个列中。值是雇员表的外键varchars。每列代表一个任务,因此同一员工可能会被分配到记录中的多个任务,并且这些任务在记录之间会有所不同。我该如何有效地做到这一点?基本上是替换整个表中所有不同列的东西。

I want to do this but the value exists in multiple columns of the same type. The values are foreign keys varchars to an employee table. Each column represents a task, so the same employee may be assigned to several tasks in a record and those tasks will vary between records. How can I do this effectively? Basically something of a replace all accross varying columns throughout a table.

感谢您的帮助或建议。

干杯,圣地亚哥的
〜ck

Cheers, ~ck in San Diego

推荐答案

这应该可以解决问题:

UPDATE table1
SET field1 = replace(field1, 'oldstring', 'newstring'),
    field2 = replace(field2, 'oldstring2', 'newstring2')

等...

这篇关于如何在SQL Server中使用“替换”更新多个列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆