22,300
社区成员




DECLARE @T NVARCHAR(20)
SET @T='#1=0 AND #2>-5'
declare @t table(id int,value int)
insert @t
select 1,0 union all
select 2,1 union all
select 3,3 union all
select 4,1 union all
select 5,2
declare @s varchar(20);declare @result varchar(20)
set @s='#1=0 AND #2>-5';set @result='#1=0 AND #2>-5'
select @result=replace(@result,'#'+convert(char(1),id),convert(char(1),value))
from @t where patIndex('%#'+convert(char(1),id)+'%',@s)>0
select @result
--------------------
0=0 AND 1>-5
declare @tb table (
ID int,
VALUE int)
insert @tb select
1, 0
union all select
2, 1
union all select
3, 3
union all select
4, 1
union all select
5, 2
DECLARE @T NVARCHAR(20)
SET @T='#1=0 AND #2>-5'
select @t=replace (@t,'#'+cast(id as varchar(20)),cast(VALUE as varchar(20)))
from @tb
where charindex('#'+cast(id as varchar(20)),@t)>0
print @t
--结果
0=0 AND 1>-5
SET @T='#1=0 AND #2>-5';
SET @T = REPLACE(REPLACE(@T,'#2','1'),'#1','0');