如题,表tbl
name cn
fda,o
aa,o=
bb,3,o
如何将name中",o"前面的字符串截取下来保存到cn列中
------解决方案--------------------
- SQL code
declare @表tbl table (name varchar(10),cn varchar(10))insert into @表tblselect 'fda,o',null union allselect 'aa,o=',null union allselect 'bb,3,o',nullupdate @表tbl set cn=left(name,charindex(',o',name)-1)select * from @表tbl/*name cn---------- ----------fda,o fdaaa,o= aabb,3,o bb,3*/
------解决方案--------------------
- SQL code
update t set cn=substring(name,1,charindex(',o',name)-1)
------解决方案--------------------
- SQL code
update tb set cn=substring(name,1,charindex(',o',name)-1) where charindex(',o',name) > 0