当前位置: 代码迷 >> Sql Server >> 怎样去掉SQL里同一列里每行不想要的内容,每行不想要的内容都不同啊该如何解决
  详细解决方案

怎样去掉SQL里同一列里每行不想要的内容,每行不想要的内容都不同啊该如何解决

热度:93   发布时间:2016-04-27 17:14:18.0
怎样去掉SQL里同一列里每行不想要的内容,每行不想要的内容都不同啊
怎样去掉SQL里同一列里每行不想要的内容,每行不想要的内容都不同啊

------解决方案--------------------
SQL code
create function getLastLetterPosition 
(@str nvarchar(100))
returns int
as
begin
declare @i int
set @i=1
while unicode(substring(@str,@i,1)) <255
set @[email protected]+1
return @i-1
end
go
create table tb(书名 nvarchar(20))
insert into tb select 'abc 你是谁'
union all select 'bcd 怎么样'
union all select 'bdf 为什么'
go
select left(书名,dbo.getLastLetterPosition(书名)) as 英文书名 from tb
/*
英文书名
--------------------
abc
bcd
bdf

(3 行受影响)

*/
go
drop function getLastLetterPosition
drop table tb
  相关解决方案