drop table #temp1,#temp2
create table #temp1
(
a varchar(30),
b varchar(30)
)
create table #temp2
(
c varchar(30),
d varchar(30),
e int
)
insert into #temp1
select '#1', 'a,b,c'
union all
select '#1', 'd,e,f'
insert into #temp2
select '#1', 'a', 1
union all
select '#1', 'b', 2
union all
select '#1', 'c', 3
union all
select '#1', 'd', 4
union all
select '#1', 'e', 5
union all
select '#1', 'f', 6
select * from #temp1
select * from #temp2
-- 想得到结果:
-- #1 a,b,c 6
-- #1 d,e,f 15
1、首先非常感谢rainee007的回答
2、实现我也已经实现,只是用游标,不理想,想用一些比较简单的语句来实现。
3、项目已经上线,改变结构的思路是好的,但已不现实。
|