怎么实现这个SQL问题?
times | number |
2006-1 | 5 |
2006-2 | 10 |
2006-5 | 8 |
2006-8 | 16 |
2006-12 | 9 |
问题: 上表左列内容不全,1-12个月少了7个月,请用T-SQL语言实现,补全左列内容,补上的左列对应的右列值为0,
上表在数据库中不变.
求问题的代码....
谢谢!
如果还不太清楚请问我.....
谢谢!!!
create table #asset(times varchar(10),number int)
insert #asset
select '2006-1',5 union all
select '2006-2',10 union all
select '2006-5',8 union all
select '2006-8',16 union all
select '2006-12',9
select top 12 mon=identity(int,1,1) into #mon from syscolumns
select times='2006-'+ltrim(a.mon),number=isnull(b.number,0) from #mon a left join #asset b on '2006-'+ltrim(a.mon)=b.times
drop table #mon,#asset