首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

SQLSERVER里怎么剔除:字符串中除了数字的字符,另外怎么剔除除了大小写字母的字符

2012-02-29 
SQLSERVER里如何剔除:字符串中除了数字的字符,另外如何剔除除了大小写字母的字符SQLSERVER里如何剔除:字符

SQLSERVER里如何剔除:字符串中除了数字的字符,另外如何剔除除了大小写字母的字符
SQLSERVER里如何剔除:字符串中除了数字的字符,另外如何剔除除了大小写字母的字符

[解决办法]
declare @str varchar(1000)
set @str = '21838asdf21jj '
while patindex( '%[^0-9]% ',@str)> 0
set @str = stuff(@str,patindex( '%[^0-9]% ',@str),1, ' ')
select @str

--结果
2183821

(所影响的行数为 1 行)
[解决办法]
create table T(col varchar(100))
insert T select '1aa23 '
insert T select 'bb45 '
insert T select '67cc '

while @@rowcount <> 0
update T set col=stuff(col, patindex( '%[^0-9]% ', col), 1, ' ')
where patindex( '%[^0-9]% ', col)> 0

select * from T

--result
col
----------------------------------------------------------------
123
45
67

(3 row(s) affected)

热点排行