日期:2014-05-18 浏览次数:20625 次
declare @str varchar(200)
select @str=@str+'/'+left(col,charindex(' ',col)) from test
print right(@str,len(@str)-1)
------解决方案--------------------
--> 测试数据:[test]
if object_id('[test]') is not null drop table [test]
create table [test]([col] varchar(20))
insert [test]
select '钢材 10*10' union all
select '木地板 10*20'
go
declare @str varchar(200)
set @str=''
select @str=@str+'/'+left(col,charindex(' ',col)-1) from test
print right(@str,len(@str)-1)
/*
钢材/木地板
*/
------解决方案--------------------
select left('钢材 10*10',CHARINDEX(' ','钢材 10*10')) as a
------解决方案--------------------
select left('钢材 10*10',CHARINDEX(' ','钢材 10*10')-1) as a
------解决方案--------------------
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([col] varchar(20))
insert [tb]
select '钢材 10*10' union all
select '木地板 10*20'
go
select left(col,charindex(' ',col)-1) as col from tb
/**
col
--------------------
钢材
木地板
(2 行受影响)
**/
------解决方案--------------------
select right(col,len(col)-charindex(' ',col)) as col from tb
------解决方案--------------------