当前位置: 代码迷 >> Sql Server >> 怎么截取字符串
  详细解决方案

怎么截取字符串

热度:105   发布时间:2016-04-27 19:47:16.0
如何截取字符串?
abcd;defg
如何分成
abcd       defg

------解决方案--------------------
declare @str varchar(40)
set @str= 'abcd;defg '

select left(@str,charindex( '; ',@str)-1),stuff(@str,1,charindex( '; ',@str), ' ')

------解决方案--------------------
abcd;defg
如何分成
abcd defg
--------------

--这样?
declare @str varchar(100)
set @str= 'abcd;efgh '
print @str
set @str=replace(@str, '; ', ' ')
print @str
go

--这样?
declare @str varchar(100)
set @str= 'abcd;efgh '
while charindex( '; ',@str)> 0
begin
print left(@str,charindex( '; ',@str)-1)
set @str=right(@str, len(@str)-charindex( '; ',@str))
end
print @str
go
  相关解决方案