34,838
社区成员




if object_id('[TB]') is not null drop table [TB]
go
create table [TB]([name] nvarchar(28))
insert [TB]
select N'中国建设银行北京分行' union all
select N'中国建设银行秦皇岛支行' union all
select N'中国建设银行全球去去去去分行'
select stuff([name],1,6,'')from [tb]
/*
-----------------------
北京分行
秦皇岛支行
全球去去去去分行
(3 個資料列受到影響)
*/
----------------------------------------------------------------
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([name] varchar(28))
insert [tb]
select '中国建设银行北京分行' union all
select '中国建设银行秦皇岛支行' union all
select '中国建设银行全球去去去去分行'
--------------开始查询--------------------------
select stuff([name],1,6,'') from tb
select replace([name],'中国建设银行','') from tb
----------------结果----------------------------
/*
----------------------
北京分行
秦皇岛支行
全球去去去去分行
(所影响的行数为 3 行)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
北京分行
秦皇岛支行
全球去去去去分行
*/
----------------------------------------------------------------
-- Author :fredrickhu(小F 向高手学习)
-- Date :2009-08-13 09:37:41
----------------------------------------------------------------
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([name] varchar(28))
insert [tb]
select '中国建设银行北京分行' union all
select '中国建设银行秦皇岛支行' union all
select '中国建设银行全球去去去去分行'
--------------开始查询--------------------------
select stuff([name],1,6,'') from tb
select replace([name],'中国建设银行','') from tb
----------------结果----------------------------
/*
----------------------
北京分行
秦皇岛支行
全球去去去去分行
(所影响的行数为 3 行)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
北京分行
秦皇岛支行
全球去去去去分行
*/
if object_id('[TB]') is not null drop table [TB]
create table [TB]([name] varchar(28))
insert [TB]
select '中国建设银行北京分行' union all
select '中国建设银行秦皇岛支行' union all
select '中国建设银行全球去去去去分行'
select name=replace(name,'中国建设银行','') from [TB]
更新原表
update tb set name=STUFF(name,1,charindex('行',name),N'') where name='中国建设银行'
select * from tb
查询
SELECT REPLACE(NAME,'中国建设银行','') FROM TB
/*
name
北京分行
秦皇岛支行
全球去去去去分行
*/
select repalce([name],'中国建设银行','') from tb
SELECT REPLACE(NAME,'中国建设银行','') FROM TB
/***********************************************
--> 测试数据:[TB]
--> 测试时间:2009-08-13 09:32:35
--> 我的淘宝:<<戒色坊>> http://shop36766744.taobao.com/
***********************************************/
if object_id('[TB]') is not null drop table [TB]
create table [TB]([name] varchar(28))
insert [TB]
select '中国建设银行北京分行' union all
select '中国建设银行秦皇岛支行' union all
select '中国建设银行全球去去去去分行'
select name=replace(name,'中国建设银行','') from [TB]
/*
name
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
北京分行
秦皇岛支行
全球去去去去分行
(3 行受影响)
*/
drop table TB
replace(name,'中国建设银行','')