老凶在华为,不该提这个问题耶。呵呵大致如下:declare @sstr char(20)
select @sstr='123.23*452.2'declare @aaa decimal(18, 6), @bbb decimal(18, 6)select @aaa = CONVERT(decimal(18,6),SUBSTRING(@sstr,1,CHARINDEX('*',@sstr)-1))
select @bbb = CONVERT(decimal(18,6),SUBSTRING(@sstr,CHARINDEX('*',@sstr)+1,LEN(@sstr)-CHARINDEX('*',@sstr)))select @aaa, @bbb
select @sstr='123.23*452.2'declare @aaa decimal(18, 6), @bbb decimal(18, 6)select @aaa = CONVERT(decimal(18,6),SUBSTRING(@sstr,1,CHARINDEX('*',@sstr)-1))
select @bbb = CONVERT(decimal(18,6),SUBSTRING(@sstr,CHARINDEX('*',@sstr)+1,LEN(@sstr)-CHARINDEX('*',@sstr)))select @aaa, @bbb
不过如果是要在存储过程中拆分字符串的话,可以使用字符串类型的一些函数啊,比如先用定位函数找出“*”的位置(你是否能保证*就只有一个?),然后再分别取子字符串不就行了,大不了么转换类型成数字型的,呵呵。
在sybase当中,可以使用charindex('*',YourString)定位,然后用substring(YourString,1,i-1)/*i为*号的位置,这里第三个参数的意义是子串的长度*/和substring(YourString,i+1,lengthOfYourString-i)得到前后两个子串。
不知道是否达到你的目的?
create table #temp (id int,value varchar(10))
select @tstr='4*5*4.34*5.78',@id=1
while patindex('%*%',@tstr)>0 begin
insert into #temp values(@id,substring(@tstr,1,patindex('%*%',@tstr)-1))
select @tstr=substring(@tstr,patindex('%*%',@tstr)+1,len(@tstr)-patindex('%*%',@tstr)),@id=@id+1
end
select * from #temp
drop table #temp