if object_id('[A]') is not null drop table [A]
create table A ( time datetime,quantity1 varchar(20))
go
insert into A
select '2014/07/17','5' union all
select'2014/07/18','6'
go
if object_id('[B]') is not null drop table [B]
create table B ( time datetime,quantity2 varchar(20))
insert into B
select'2014/07/17','7'
go
select A.time,A.quantity1,Isnull(B.quantity2,0)as [quantity2] from A left join B on A.time=B.time--time quantity1 quantity2
--2014-07-17 00:00:00.000 5 7
--2014-07-18 00:00:00.000 6 0
create table A ( time datetime,quantity1 varchar(20))
go
insert into A
select '2014/07/17','5' union all
select'2014/07/18','6'
go
if object_id('[B]') is not null drop table [B]
create table B ( time datetime,quantity2 varchar(20))
insert into B
select'2014/07/17','7'
go
select A.time,A.quantity1,Isnull(B.quantity2,0)as [quantity2] from A left join B on A.time=B.time--time quantity1 quantity2
--2014-07-17 00:00:00.000 5 7
--2014-07-18 00:00:00.000 6 0
感谢,但是我已经写好了
SELECT TOP (100) PERCENT (CASE WHEN dbo.restore_dianji.time IS NULL THEN dbo.restore_qudong.time ELSE dbo.restore_dianji.time END) AS 日期,
dbo.restore_dianji.quantity AS 电机, dbo.restore_qudong.quantity AS 驱动
FROM dbo.restore_dianji RIGHT OUTER JOIN
dbo.restore_qudong ON dbo.restore_dianji.time = dbo.restore_qudong.time
ORDER BY dbo.restore_dianji.time DESC