简体   繁体   English

在SQL Server 2008 R2的列中的数字后删除字符

[英]Removing characters after numbers in a column in SQL Server 2008 R2

I want to delete the characters after numbers in one of my columns: 我想删除其中一列中数字后面的字符:

Column values are like this : 列值如下所示:

2GB 
3G
28GB
7G
90G

as you can see there is no pattern in these numbers except I have a one or two digits number and letter G or GB after them. 如您所见,这些数字没有模式,除了我后面有一个或两个数字以及字母GGB

What query can detect the numbers and delete the characters after that? 哪个查询可以检测到数字并在此之后删除字符?

Thanks 谢谢

Try this.. 尝试这个..

drop table #t
create table #t(id varchar(10))
insert into #t values('2GB'), 
            ('3G'),
            ('28GB'),
            ('7G'),
            ('90G')


            update #t
            set id=substring(id,0,PATINDEX('%[GB]%',id)) from #t
            select * from #t

See Demo 观看演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM