22,209
社区成员
发帖
与我相关
我的任务
分享
-- 超过 8000 了,试试这个
create table test(mobile varchar(50), content varchar(10))
go
insert into test values
('150137447xx', '验证码'),
('154866256xx','456'),
('154841255xx,189554742xx,155668484xx','789')
go
SELECT a.content,b.v FROM (
SELECT t.content,CONVERT(XML,'<n>'+REPLACE(t.mobile,',','</n><n>')+'</n>') c
FROM test t
) a CROSS APPLY(SELECT n.value('.','varchar(20)') v FROM a.c.nodes('n') k(n)) b
go
drop table test
go
(3 行受影响)
content v
---------- --------------------
验证码 150137447xx
456 154866256xx
789 154841255xx
789 189554742xx
789 155668484xx
(5 行受影响)
-- 知音啊,,你懒的程度,都快赶上我了。。
create table test(mobile varchar(50), content varchar(10))
go
insert into test values
('150137447xx', '验证码'),
('154866256xx','456'),
('154841255xx,189554742xx,155668484xx','789')
go
create table b( mobile varchar(50), content varchar(10))
go
-- 创建这个过程
create proc sp_xxx
as
begin
with m as (
select mobile + ',' mobile, content from test
)
insert into b
select reverse(substring(reverse(substring(m.mobile,1,s.number-1)),
0 ,
charindex(',',reverse(substring(m.mobile,1,s.number-1)) +',')
)
) as item ,
m.content
from m, master..spt_values s
where len(m.mobile) >=s.number and s.type ='p'
and substring(m.mobile,s.number,1) =','
end
go
-- 执行这个过程
exec sp_xxx
go
-- 查询表 b 的数据
select * from b
go
drop proc sp_xxx
go
drop table test , b
go
(3 行受影响)
(5 行受影响)
mobile content
-------------------------------------------------- ----------
150137447xx 验证码
154866256xx 456
154841255xx 789
189554742xx 789
155668484xx 789
(5 行受影响)
create table test(mobile varchar(50), content varchar(10))
go
insert into test values
('150137447xx', '验证码'),
('154866256xx','456'),
('154841255xx,189554742xx,155668484xx','789')
go
with m as (
select mobile + ',' mobile, content from test
)
select reverse(substring(reverse(substring(m.mobile,1,s.number-1)),
0 ,
charindex(',',reverse(substring(m.mobile,1,s.number-1)) +',')
)
) as item ,
m.content
from m, master..spt_values s
where len(m.mobile) >=s.number and s.type ='p'
and substring(m.mobile,s.number,1) =','
go
drop table test
go
(3 行受影响)
item content
--------------------------------------------------- ----------
150137447xx 验证码
154866256xx 456
154841255xx 789
189554742xx 789
155668484xx 789
(5 行受影响)