使用拆分值更新列值

Update column values with splited values

我有一个sqltableProduct:

id name value   type
1  a    abs#123  1
2  b    abs#123  2
3  c    abs#123  1

如何使用 # 之前的值更新产品类型 1 的值列,这意味着 abs#123 将是 abs,因此我必须拆分值列通过 #?

使用Leftcharindex函数。试试这个。

update Product 
set value=left(value,charindex('#',value)-1)
where type=1

或使用Substring

update Product 
set value=substring(value,1,charindex('#',value)-1)
where type=1