34,838
社区成员




--1、
update [table] set a=replace(a,' ','')
--2、
update [table] set b=right('0000000000'+b,10)
drop table smneo
create table smneo
(
id int,
a varchar(10),
b varchar(10)
)
delete from smneo
insert into smneo
select '1','aaaa','1' union all
select '2',' bbbb','22'union all
select '3','cccc ','333'union all
select '4','dd dd','4444'union all
select '5',' ee ee ','5555'
select id, replace(a,' ', '') from smneo
select id, REPLICATE('0', 10 - DATALENGTH(b)) + b from smneo
============================
id, a
1 aaaa
2 bbbb
3 cccc
4 dddd
5 eeee
===========================
id, b
1 0000000001
2 0000000022
3 0000000333
4 0000004444
5 0000005555
IF OBJECT_ID('TB')IS NOT NULL DROP TABLE TB
GO
CREATE TABLE TB(a VARCHAR(10),b varchar(10))
insert tb select ' ad asd ','12'
insert tb select 'adad sd ','ab'
--1
update tb set a=replace(a,' ','')
--2
update tb set b=right('0000000000'+b,10)
select * from tb
/*a b
---------- ----------
adasd 0000000012
adadsd 00000000ab*/
---2
update tb set b=right('0000000000'+b,10)
--1
update tb set a=replace(a,' ','')
--2