【问题标题】:Removing characters after numbers in a column in SQL Server 2008 R2在 SQL Server 2008 R2 中的列中删除数字后的字符
【发布时间】:2014-08-09 09:18:32
【问题描述】:

我想删除我的一列中数字后面的字符:

列值是这样的:

2GB 
3G
28GB
7G
90G

如您所见,这些数字中没有任何模式,除了我有一个或两位数字和字母GGB

什么查询可以检测到数字并删除之后的字符?

谢谢

【问题讨论】:

标签: sql sql-server sql-server-2008-r2 charindex


【解决方案1】:

试试这个..

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多