27,579
社区成员
发帖
与我相关
我的任务
分享
create table tb
(
users varchar(10)
)
insert into tb
select ',a,b ' union all
select ' ,a,b, ' union all
select 'ab ' union all
select ' a,b' union all
select 'a,b' union all
select ' ' union all
select ' ' union all
select null
UPDATE tb SET users=replace(' '+LTRIM(RTRIM(replace(LTRIM(RTRIM(users)),',',' ')))+' ',' ',',')
from tb where users is not null and users<>''
SELECT * FROM TB
-----------
users
,a,b,
,a,b,
,ab,
,a,b,
,a,b,
NULL
select case when users is null or users ='""' or (left(users,1)=',' and right(users,1)=',') then users
else ','+users+',' end as users from t1
update A set users=replace(' '+users+' ',' ',',') where user is not null or user <>''
select case when user=null or user ='' then user else replace(' '+users+' ',' ',',') end