读书人

取第一个汉字前的所有字符()

发布时间: 2012-06-02 14:16:14 作者: rapoo

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


[解决办法]

SQL code
if object_id('[tb]') is not null drop table [tb]gocreate table [tb]([col] varchar(16))insert [tb]select 'VD-1106B' union allselect 'VG-0806F' union allselect 'VK-16A' union allselect 'VD-1106B床头柜' union allselect 'VG-0806F五门路轨' union allselect 'VK-16A方几'goselect left(col+'吖',patindex('%[吖-]%',col+'吖')-1) as col from tb/**col------------------VD-1106BVG-0806FVK-16AVD-1106BVG-0806FVK-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('%[吖……

读书人网 >SQL Server

热点推荐