日期:2014-05-19  浏览次数:20717 次

如何查询字段中的%,如何替换%全角的百分号
如何查询字段中的%,如何替换%全角的百分号

------解决方案--------------------
update tb set col=replace(col, '% ', '% ')
------解决方案--------------------
--如何替换%全角的百分号
Create Table TEST
(ID Int,
Name Varchar(100))
Insert TEST Select 1, '2%3 '
Union All Select 2, '%23 '
Union All Select 2, '23 '
GO
Update TEST Set Name = Replace(Name, '% ', '% ')

Select * From TEST
GO
Drop Table TEST
--Result
/*
ID Name
1 2%3
2 %23
2 23
*/
------解决方案--------------------
select * from table where charindex( '% ',列名)> 0
update table set 列名=replace(列名, '% ', '% ')
------解决方案--------------------
在保留字如%上加上[]进行运算.
------解决方案--------------------

update table set 列名=replace(列名, '% ', '% ')
Create Table TEST2
(ID Int,
Name Varchar(100))
Insert TEST2 Select 1, '2%3 '
Union All Select 2, '%23 '
Union All Select 2, '23 '
GO
Select * From TEST2 Where Name Like '% '+QUOTENAME ( '% ')+ '% '
GO
Drop Table TEST2
------解决方案--------------------
update table set 列名=replace(列名, '% ', '% ')