2016-06-23 3 views
0

このVBScriptを修正して、ドロップダウンリストのデータをSQLクエリの変数として使用できるようにするのが苦労しています。VBSドロップダウンリスト - SQLサーバから引き出されたオプション

これは私のdefault.aspページです。ここで、ユーザーは、照会する顧客と日付を選択します。私のVBSはもともと、顧客名、提出番号、および都市をデータベースから選択するように設計されていました。私が気にするのは、customerName列です。

<!DOCTYPE html> 
<html> 
<head><title></title> 
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 
    <script src="//code.jquery.com/jquery-1.10.2.js"></script> 
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 

    <script> 
     $(function() { 
     $("#datepickstart").datepicker(); 
    }); 
    </script> 

    <script> 
     $(function() { 
     $("#datepickend").datepicker(); 
    }); 
    </script> 

    <script> 
     $(function(){ 
     $("#header").load("/../header.htm"); 
    }); 
    </script> 
    <script language="JavaScript"> 
    function selSummary_OnChange(stype,customer) { 
     document.frmSummary.customer.Value = customer; 
     document.frmSummary.Summary.Value = stype; 
     document.frmSummary.action = "default.asp"; 
     document.frmSummary.submit(); 
    } 
    </script> 
</head> 

<body> 

    <div id="header"></div> 

<form action="billing.asp" id="billing" method="post" target="_blank"> 
    <table> 
     <tr><th colspan=4><b>TESTING!</b></th></tr> 
     <tr> 
      <td>Customer:</td> 
      <td><select name="customer"> 
       <% if Request.Form("customer") = "0,0,0" then %> 
        <option value="0" selected>All 
       <% else %> 
        <option value="0">All 
       <% end if %> 
       <% 
         dim DBCONN 
       set DBCONN = Server.CreateObject("ADODB.Connection") 
       DBCONN.CommandTimeout = 60000 
       DBCONN.ConnectionTimeout = 60000 
       DBCONN.Open "DSN=***;UID=***;PWD=***" 
       set DBConnection = DBCONN 
       strSQL = "select customerName from log.dbo.customer order by customerName" 
       'set DBConnection = GetDataConnection 
       set DBQuery = Server.CreateObject("ADODB.Command") 
       DBQuery.ActiveConnection = DBConnection 
       DBQuery.CommandType = 1 
       DBQuery.CommandText = strSQL 
       set dbCS = DBQuery.Execute 

       dbCS.MoveFirst 
       while not dbCS.EOF 
        strcustomerIdentifier = dbCS.Fields("customerNo").Value & "," & dbCS.Fields("SubNo").Value & "," & dbCS.Fields("city") 
        Response.Write("<option value='" & strcustomerIdentifier & "'") 
        if Request.Form("customer") = strcustomerIdentifier then 
         Response.Write("selected") 
        end if 
        Response.Write(">" & dbCS.Fields("customerName").Value & chr(13)) 
        dbCS.MoveNext 
       wend 
       Set dbCS = Nothing 
       %> 
       </select></td> 
      <td>Start Date: <input type="text" name="datepickstart" id="datepickstart"></td> 
      <td>End Date: <input type="text" name="datepickend" id="datepickend"></td> 
     </tr> 
     <tr> 
      <td><input type="submit" value="Submit" id="billingsubmit"></td> 
     </tr> 
    </table> 
    </form> 

</body> 
</html> 

そこから私たちはbilling.aspに行きます。このページは、ユーザーの以前の入力に基づいてHTMLテーブルを吐き出す必要があります。顧客テーブルの選択をSQL文字列の変数として使用できるようにしたいのですが、私の試みが正しく機能していないので、それを正しく達成する方法がわかりません。

「すべて」はSQLクエリで成功する変数ではないので、2つの異なるクエリを呼び出そうとしています。それらの間の唯一の違いは、単一の顧客を指定するための(および「+顧客+」)の追加です。

billing.asp

<%@ Language=VBScript %> 
<html> 
<head><title></title> 
</head> 
<body> 
<% 
dim startdate 
    startdate = request.form("datepickstart") 
dim enddate 
    enddate = request.form("datepickend") 
dim customer 
    customer = request.form("customer") 
%> 

<% 
    dim dbconn 
    set dbconn = server.createobject("adodb.connection") 
    DBCONN.CommandTimeout = 60000 
    DBCONN.ConnectionTimeout = 60000 
    dbconn.open "dsn=***;uid=***;pwd=***" 

    dim billingtrans 
    dim sqlstr 
if request.form("customer")="All" 
then 
    sqlstr = "SELECT sq.*, sq.Total - sq.[Update] as Inquiry from (select f.customerName, t.[city], sum (t.TransactionCount) as Total, sum (case when ([format] in (23,25,38) or [format] between 400 and 499 or [format] between 800 and 899) then t.TransactionCount else 0 end) as [Update] FROM [log].[dbo].[TransactionSummary] t INNER JOIN [log].[dbo].[customer] f on t.customerNo = f.customerNo and t.city = f.city and t.subno = f.subno where t.transactiondate between '" + startdate + "' and '" + enddate + "' group by f.customerName,t.city) sq" 
else 
    sqlstr = "SELECT sq.*, sq.Total - sq.[Update] as Inquiry from (select f.customerName, t.[city], sum (t.TransactionCount) as Total, sum (case when ([format] in (23,25,38) or [format] between 400 and 499 or [format] between 800 and 899) then t.TransactionCount else 0 end) as [Update] FROM [log].[dbo].[TransactionSummary] t INNER JOIN [log].[dbo].[customer] f on t.customerNo = f.customerNo and t.city = f.city and t.subno = f.subno where t.transactiondate between '" + startdate + "' and '" + enddate + "' and '" + customer + "' group by f.customerName,t.city) sq" 
set billingtrans = server.createobject("adodb.recordset") 
billingtrans.open sqlstr, dbconn 
%> 

<table id="billing"> 
     <tr> 
      <td>Customer</td> 
      <td>City</td> 
      <td>Update</td> 
      <td>Inquiry</td> 
      <td>Total</td> 
     </tr> 
<% while not billingtrans.eof %> 
     <tr> 
      <td><% =billingtrans("customerName") %></td> 
      <td><% =billingtrans("city") %></td> 
      <td><% =billingtrans("Update") %></td> 
      <td><% =billingtrans("Inquiry") %></td> 
      <td><% =billingtrans("Total") %></td> 
     </tr> 
<% billingtrans.movenext 
    wend 
    billingtrans.close 
    dbconn.close 
%> 
</table> 
</body> 
</html> 

この上の任意のヘルプは素晴らしいことです。

答えて

0

ループの外側にある[すべて]オプションを移動します。

   <select Name="customersel" id="customersel"> 
       <% if Request.Form("customersel") = "0" then %> 
       <option value="0" selected>All 
       <% else %> 
       <option value="0">All 
       <% end if 
       do until customersel.EOF%> 
       <option value="<%= customersel("customername") %>"><%= customersel("customername") %></option> 

       <% 
       customersel.MoveNext 
       Loop %> 
       </select> 

NB do until...loopwhile not...wendに代わるものです。どちらも有効ですが、それは単なる優先事項です。

selectedプロパティを追加するには、実際には条件文は必要ありません。 "All"オプションはリストの最初のものであるため、他のオプションが選択されていない限り表示されます。

関連する問題