当前位置: 代码迷 >> Sql Server >> 怎么查询字段中的%,怎么替换%全角的百分号
  详细解决方案

怎么查询字段中的%,怎么替换%全角的百分号

热度:83   发布时间:2016-04-27 21:28:32.0
如何查询字段中的%,如何替换%全角的百分号
如何查询字段中的%,如何替换%全角的百分号

------解决方案--------------------
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(列名, '% ', '% ')
  相关解决方案