0

我在 SQL Server 中有一个表,其中包含一个包含逗号分隔值Settings的列。settingValue

该列的示例数据:

0, 0
US, US
test@test.com, test@test.com

我想编写一个更新查询,以便该列settingValue仅显示一个应该导致的值

0
US
test@test.com

不知道从哪里开始我应该,先找到逗号()然后截断语句?

4

1 回答 1

4

如果要删除第一个逗号后的所有内容,则可以使用:

update yourtable
set col = substring(col, 1, charindex(',', col)-1)
where charindex(',', col) > 0  -- only update the rows with a comma

请参阅带有演示的 SQL Fiddle

于 2013-03-14T20:20:40.073 回答