日期:2014-05-18  浏览次数:20686 次

SQL 优化问题? ************ 页面打开特慢, 帮看看其中的SQL 有什么好的方案?

<%        

do   while   not   rs.eof    
  cigbrandcode=rs( "cigbrand ")
  printnum1=rs( "printnum1 ")
%>
<%
'---------------------   通过卷烟代码,查询卷烟名称;
sql1= "select   *   from   qjcf31_barcodeprinter.dbo.CIGBRAND   where   CIGBRANDCODE= ' "+cigbrandcode+ " ' "
rs1.open   sql1,conn,1,1        
if   not   rs1.eof   then  
cigbrand=rs1( "cigbrand ")
end   if
rs1.close

%>
        <%
'---------------------   通过卷烟代码,查询排产数/读码数;

sql1= "SELECT   sum(arrangenum)   as   arrangenum1,sum(downnum)   as   downnum1   "
sql1=sql1+ "   FROM   (   "
sql1=sql1+ "   SELECT   *   FROM   qjcf31_barcodeprinter.dbo.arrange   where   cigbrandcode= ' "+cigbrandcode+ " '     and   (convert(char(10),producedate,120)> = ' "+begindate+ " '   and   convert(char(10),producedate,120) <= ' "+enddate+ " ')   "  
sql1=sql1+ "   UNION   SELECT   *   FROM   QJCF32_BARCODEPRINTER.dbo.arrange   where   cigbrandcode= ' "+cigbrandcode+ " '     and   (convert(char(10),producedate,120)> = ' "+begindate+ " '   and   convert(char(10),producedate,120) <= ' "+enddate+ " ')   "
sql1=sql1+ "   UNION   SELECT   *   FROM   QJCF33_BARCODEPRINTER.dbo.arrange   where   cigbrandcode= ' "+cigbrandcode+ " '     and   (convert(char(10),producedate,120)> = ' "+begindate+ " '   and   convert(char(10),producedate,120) <= ' "+enddate+ " ')   "
sql1=sql1+ "   UNION   SELECT   *   FROM   QJCF34_BARCODEPRINTER.dbo.arrange   where   cigbrandcode= ' "+cigbrandcode+ " '     and   (convert(char(10),producedate,120)> = ' "+begindate+ " '   and   convert(char(10),producedate,120) <= ' "+enddate+ " ')   "
sql1=sql1+ "   UNION   SELECT   *   FROM   QJCF35_BARCODEPRINTER.dbo.arrange   where   cigbrandcode= ' "+cigbrandcode+ " '     and   (convert(char(10),producedate,120)> = ' "+begindate+ " '   and   convert(char(10),producedate,120) <= ' "+enddate+ " ')   "
sql1=sql1+ "   UNION   SELECT   *   FROM   QJCF36_BARCODEPRINTER.dbo.arrange   where   cigbrandcode= ' "+cigbrandcode+ " '     and   (convert(char(10),producedate,120)> = ' "+begindate+ " '   and   convert(char(10),producedate,120) <= ' "+enddate+ " ')   "
sql1=sql1+ "   UNION   SELECT   *   FROM   QJCF37_BARCODEPRINTER.dbo.arrange   where   cigbrandcode= ' "+cigbrandcode+ " '     and   (convert(char(10),producedate,120)> = ' "+begindate+ " '   and   convert(char(10),producedate,120) <= ' "+enddate+ " ')   "
sql1=sql1+ "   UNION   SELECT   *   FROM   QJCF38_BARCODEPRINTER.db