34,590
社区成员
发帖
与我相关
我的任务
分享
create table t(id int identity(1,1),name varchar(100))
declare @s varchar(1000)
set @s='张三,李四,jinjazz'
insert into t(name)
select replace(reverse((left(s,charindex(',',s)))),',','') as S from(
select r,reverse(left(@s,r))+',' as s
from(
select (select count(*) from sysobjects where name<=t.name ) as r
from sysobjects t
)a where r<=len(@s)
and left(@s+',',r+1) like '%,'
)t order by r
select * from t
drop table t
/*
(3 行受影响)
id name
----------- ----------------------------------------------------------------------------------------------------
1 张三
2 李四
3 jinjazz
(3 行受影响)
*/
if not object_id('tb1') is null
drop table tb1
Go
Create table tb1([id] int identity,[numb] int)
Insert tb1
select 20 union all
select 30 union all
select 50
select * from tb1
/*
id numb
----------- -----------
1 20
2 30
3 50
(3 行受影响)
*/
drop table tb1
create table test(a int identity(1,1),name varchar(20))
insert into test(name) values('张三')