日期:2014-05-17 浏览次数:20762 次
CREATE TABLE [dbo].[list](
[GUID] [varchar](50) NOT NULL,
[title] [varchar](50) NULL,
[monthTable] [varchar](50) NULL
) ON [PRIMARY]
insert into list(guid,title,monthtable) values('111','标题1','info201201')
insert into list(guid,title,monthtable) values('222','标题2','info201202')
insert into list(guid,title,monthtable) values('333','标题3','info201203')
insert into list(guid,title,monthtable) values('444','标题4','info201204')
CREATE TABLE [dbo].[info201201](
[GUID] [varchar](50) NOT NULL,
[msg] [varchar](50) NULL
) ON [PRIMARY]
CREATE TABLE [dbo].[info201202](
[GUID] [varchar](50) NOT NULL,
[msg] [varchar](50) NULL
) ON [PRIMARY]
CREATE TABLE [dbo].[info201203](
[GUID] [varchar](50) NOT NULL,
[msg] [varchar](50) NULL
) ON [PRIMARY]
CREATE TABLE [dbo].[info201204](
[GUID] [varchar](50) NOT NULL,
[msg] [varchar](50) NULL
) ON [PRIMARY]
insert into info201201(guid,msg) values('111','内容1')
insert into info201202(guid,msg) values('222','内容2')
insert into info201203(guid,msg) values('333','内容3')
insert into info201204(guid,msg) values('555','内容5')
with t
as(
select * from info201201
union all
select * from info201202
union all
select * from info201203
union all
select * from info201204
)
select
l.GUID,
l.title,
t.msg
from
[dbo].[list] l
left join
t
on
l.GUID=t.GUID
/*
GUID title msg
---------------------------------
111 标题1 内容1
222 标题2 内容2
333 标题3 内容3
444 标题4 NULL
*/