字符串处理的问题
CCCIL-云南-法务-法务
CCCIL-云南-需求满足-基建工程
CCCIL-云南-总经办-总经办
CCCIL-云南-法务
以上的字符串,怎样准确的得到:
CCCIL-云南-法务
CCCIL-云南-需求满足
CCCIL-云南-总经办
CCCIL-云南-法务
这样的数据
也就是包括第三个'-'符号以后的数据都不要了
[解决办法]
- SQL code
---测试数据---if object_id('[tb]') is not null drop table [tb]gocreate table [tb]([col] varchar(28))insert [tb]select 'CCCIL-云南-法务-法务' union allselect 'CCCIL-云南-需求满足-基建工程' union allselect 'CCCIL-云南-总经办-总经办' union allselect 'CCCIL-云南-法务' ---查询---select col=left(col,len(col)-charindex('-',reverse(col)))from tb---结果---col----------------------------CCCIL-云南-法务CCCIL-云南-需求满足CCCIL-云南-总经办CCCIL-云南(4 行受影响)
[解决办法]如需要阅读该回复,请登录或注册CSDN!