AAAAAA ABC AA
BBB ABC SSSSS
CCCC ABC LLLLLL
里的ABC都替换成 XY
AAAAAA XY AA
BBB XY SSSSS
CCCC XY LLLLLL
3 个解决方案
#1
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-09-06 16:07:15
-- Version:
-- Microsoft SQL Server 2014 (CTP1) - 11.0.9120.5 (X64)
-- Jun 10 2013 20:09:10
-- Copyright (c) Microsoft Corporation
-- Enterprise Evaluation Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------------------------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([name] varchar(13))
insert [huang]
select 'AAAAAAABCAA' union all
select 'BBBABCSSSSS' union all
select 'CCCCABCLLLLLL'
--------------开始查询--------------------------
select name,REPLACE(name,'abc','xy')
from [huang]
----------------结果----------------------------
/*
name
------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
AAAAAAABCAA AAAAAAxyAA
BBBABCSSSSS BBBxySSSSS
CCCCABCLLLLLL CCCCxyLLLLLL
*/
#2
用Replace函数就可以了。
#3
replace(),stuff()好多字符串替换函数都可以使用。
#1
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-09-06 16:07:15
-- Version:
-- Microsoft SQL Server 2014 (CTP1) - 11.0.9120.5 (X64)
-- Jun 10 2013 20:09:10
-- Copyright (c) Microsoft Corporation
-- Enterprise Evaluation Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------------------------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([name] varchar(13))
insert [huang]
select 'AAAAAAABCAA' union all
select 'BBBABCSSSSS' union all
select 'CCCCABCLLLLLL'
--------------开始查询--------------------------
select name,REPLACE(name,'abc','xy')
from [huang]
----------------结果----------------------------
/*
name
------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
AAAAAAABCAA AAAAAAxyAA
BBBABCSSSSS BBBxySSSSS
CCCCABCLLLLLL CCCCxyLLLLLL
*/
#2
用Replace函数就可以了。
#3
replace(),stuff()好多字符串替换函数都可以使用。