这个问题问了好几天。虽然问题我解决了,但算法效率感觉不是很好.
declare @i int --当查询结果小于100条记录的时候就不添加空行,如果小于100行的时候添加100-Count(*)条记录到#table2里面.
select @i=count(khbh) from #table2
if @i<100
Begin
(select identity(int,1,1) as khbh,null as A,null as B,null as C, null as D,Null as E into #temp1 from (select top 100 * from sysobjects) a)
select khbh,类型,单号,限定日期,欠款金额,ordertype From #table2
union all
SELECT khbh,null,null,null,null,Null From #temp1
where #temp1.khbh>@i
drop table #temp1
end else
select * from #table2
能不能用while @i<100
begin
end; 为替代。或者有更好的办法。因为我上面的写法还要借助sysobjects
先谢谢各位朋友。
这个题目上,判断#table2的记录数是否小于100, 如果小于则用空行填补后面的行。 如果大于则什么都不做. 照样输出。
再次感谢!!! , 从上星期三到现在呀!!.