注册 登录
编程论坛 SQL Server论坛

怎样从字符串中取值

风流上进 发布于 2007-09-26 12:16, 1577 次点击
有这样一系列的字符串
100(500:0.5)(2000:0.3)0.6
80(200:0.5)(1000:0.4)0.45
600(1500:0.4)(3000:0.5)0.6

问怎么取第一个 ‘(’ 前的值

我用substring ,‘(’有时候是第3个,有时候是第4个 该怎么判断?

9 回复
#2
shuzai19852007-09-26 13:11
left(x,charindex('(',x)-1) 不知道行不行??
#3
bygg2007-09-26 13:19
select charindex(',',comName) from tablename
这就可以取到位置,再用substring

[此贴子已经被作者于2007-9-26 13:21:14编辑过]

#4
风流上进2007-09-26 13:41
能不能写具体点
#5
心中有剑2007-09-26 13:53
select left(x,charindex('(',x)) from tablename

#6
shuzai19852007-09-26 21:39
select left(x,charindex('(',x)-1) from tablename
#7
风流上进2007-09-27 08:31
问题解决了 谢谢
#8
shuzai19852007-09-27 11:42

答案贴出来啊   LZ

#9
风流上进2007-09-27 16:29
就是用的 charindex 函数

select charindex('100(500:0.5)(2000:0.3)0.6 ','(')
#10
西风独自凉2007-09-29 09:21
select left(name,charindex('(',字符串,1)-1) from 表
1