日期:2014-05-18  浏览次数:20405 次

取第一个汉字前的所有字符(在线等)
请教大侠,我想取第一个汉字前的所有字符,该怎么取?谢谢!
比如以下的行数据,我想取出字符为:VD-1106B
  VG-0806F
  VK-16A
VD-1106B床头柜
VG-0806F五门路轨
VK-16A方几


------解决方案--------------------
SQL code
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([col] varchar(16))
insert [tb]
select 'VD-1106B' union all
select 'VG-0806F' union all
select 'VK-16A' union all
select 'VD-1106B床头柜' union all
select 'VG-0806F五门路轨' union all
select 'VK-16A方几'
go

select left(col+'吖',patindex('%[吖-咗]%',col+'吖')-1) as col from tb

/**
col
------------------
VD-1106B
VG-0806F
VK-16A
VD-1106B
VG-0806F
VK-16A

(6 行受影响)
**/

------解决方案--------------------
探讨
SQL code


create table dg(descr varchar(20))

insert into dg
select 'VD-1106B床头柜' union all
select 'VG-0806F五门路轨' union all
select 'VK-16A方几'


select descr,substring(descr,1,patindex('%[吖……