zoukankan      html  css  js  c++  java
  • 删除记录的前缀

    --建表
    
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Table_1]') AND type in (N'U'))
    BEGIN
    CREATE TABLE [dbo].[Table_1](
    	[ID] [int] IDENTITY(1,1) NOT NULL,
    	[UserName] [nvarchar](50) NULL,
     CONSTRAINT [PK_Table_1] PRIMARY KEY CLUSTERED 
    (
    	[ID] ASC
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
    ) ON [PRIMARY]
    END
    go
    
    --插入测试数据
    
    insert into [Table_1]([UserName])values('asd_1');
    insert into [Table_1]([UserName])values('asd_2');
    insert into [Table_1]([UserName])values('asd_3');
    insert into [Table_1]([UserName])values('a阿斯顿sd_4');
    insert into [Table_1]([UserName])values('asd_5');
    insert into [Table_1]([UserName])values('6');
    insert into [Table_1]([UserName])values('as阿斯顿飞d_7');
    insert into [Table_1]([UserName])values('asd_8');
    
    --查看数据
    select * from table_1
    
    --更新每次修改的数据
    update table_1 set UserName='asd_1' where id=1;
    update table_1 set UserName='asd_2' where id=2;
    update table_1 set UserName='asd_3' where id=3;
    update table_1 set UserName='a阿斯顿sd_4' where id=4;
    update table_1 set UserName='asd_5' where id=5;
    update table_1 set UserName='6' where id=6;
    update table_1 set UserName='as阿斯顿飞d_7' where id=7;
    update table_1 set UserName='asd_8' where id=8;
    
    --采用stuff删除记录的前缀
    update table_1 set UserName=stuff(UserName,1,charindex('_',UserName),'')
    --采用substring删除记录的前缀
    update table_1 set UserName=substring(UserName,charindex('_',UserName)+1,len(UserName));
    --采用replace删除记录的前缀
    update table_1 set UserName=replace(UserName,substring(UserName,1,charindex('_',UserName)),'');
  • 相关阅读:
    js在字符串中提取数字
    checkbox简单例子
    递归算法及经典递归例子代码实现
    e
    MyEclipse10中启动出现OutOfMemoryError: PermGen space如何解决
    VB php JAVA关于数据库连接数过多的解决方法
    java.lang.UnsupportedClassVersionError: Bad version number in .class file
    KindEditor得不到textarea值的解决方法
    php创建读取 word.doc文档
    php 在web端读出pdf 与各种文件下载
  • 原文地址:https://www.cnblogs.com/liszt/p/1994410.html
Copyright © 2011-2022 走看看