table1表:编号 价格
12 100
13 200
15 150
18 220table2表:编号 日期 数量
12 2006-9-1 2
15 2006-8-1 1要求:在table2表 日期 等于 2006-9-1时结果编号 价格 数量
12 100 2
13 200 0
15 150 0
18 220 0
12 100
13 200
15 150
18 220table2表:编号 日期 数量
12 2006-9-1 2
15 2006-8-1 1要求:在table2表 日期 等于 2006-9-1时结果编号 价格 数量
12 100 2
13 200 0
15 150 0
18 220 0
left join table2 b on a.编号= b.编号
where datediff(dd,b.日期,'2006-9-1') = 0
left join table2 b on a.编号= b.编号
and datediff(dd,b.日期,'2006-9-1') = 0
where datediff(dd,b.日期,'2006-9-1') = 0
应为
and datediff(dd,b.日期,'2006-9-1') = 0
如果table2表 日期 要等于 2006-7-1的时候,
但table2中没有这个日期,怎么一条也不出现了
12 100 0
13 200 0
15 150 0
18 220 0
declare @t2 table(编号 int,日期 datetime,数量 int)
insert @t1
select 12, 100 union all
select 13, 200 union all
select 15, 150 union all
select 18, 220
insert @t2
select 12, '2006-9-1', 2 union all
select 15, '2006-8-1', 1select a.编号,a.价格,isnull(b.数量,0) as 数量 from @t1 a
left join @t2 b on a.编号= b.编号
and datediff(dd,b.日期,'2006-7-1') = 0/*结果
编号 价格 数量
12 100 0
13 200 0
15 150 0
18 220 0
*/
中这个方法就不能用
请问怎么修改?