SQL查询在ASP.NET中花费25秒加载页面

时间:2018-11-16 10:10:19

标签: sql asp.net sql-server tsql stored-procedures

如何提高页面加载速度以尽早获取数据?

select B.bdregno, B.srno, B.bdbillno, B.bdfees as bdfees, B.bdqty as bdqty,
       B.bdrcode as bdrcode, B.bdtno as bdtno, B.bdvdate as bdvdate, T.TNAME as TNAME 
from dbo.[test] T full outer join 
     dbo.[billdet] B 
     on T.TCODE = B.bdtcode 
where" + qr + " bdregno='" + hdfregno.Value + "' 
order by bdvdate asc, srno

查询在SQL Server中快速运行,但是在ASP.NET应用程序中,加载页面大约需要25秒。

1 个答案:

答案 0 :(得分:1)

首先,我怀疑您是否真的想要完全外部联接。我猜一个left join就足够了:

select B.bdregno, B.srno, B.bdbillno, B.bdfees, B.bdqt,
       B.bdrcode, B.bdtno, B.bdvdate, T.TNAME 
from dbo.[billdet] B left join
     dbo.[test] T 
     on T.TCODE = B.bdtcode 
where b.bdregno = ?  --'" + hdfregno.Value + "' 
order by b.bdvdate asc, srno

对于此查询,您希望在billdet(bdregno, bdtcode)上建立索引。引擎仍然需要做麦芽汁。

请注意,您应该将值作为参数传入,而不要查询字符串。