我有一个查询如下:
select column_date, field1, field2, sum(field3) from table1
where field1 like '*xyz' and
column_date between [please enter start date] and [please enter end date]
group by column_date, field1, field2
当我将两个参数框都留空时,输出为空白。但我希望它们输出如下
- 当我将两个参数框都留空时,我想显示所有记录
- 如果我将日期放在任何一个参数框中,它应该只显示该日期的记录
- 如果我将日期放在两个参数框中,它应该显示这些日期之间的所有记录。
这是我显示输出的asp代码。当我在两个文本框中插入值时它可以工作,但是如果我将其中任何一个或两个都留空,则会显示错误。
<html>
<body>
<%
dim startdate, enddate
startdate = Request.Form ("startdate")
enddate = Request.Form("enddate")
set conn = Server.CreateObject ("ADODB.Connection")
conn.open "connectionname"
set rs = Server.CreateObject ("ADODB.Recordset")
Sqlquery = "queryname '" & startdate & "', '" & enddate &'" "
rs.open sql, conn %>
<table>
<tr>
<%
For each x in rs.fields
response.write ("<th>" & x.name & "</th>")
next %> </tr>
<tr><% Do Until rs.EOF %>
<% For each x in rs.Fields %>
<td>Response.write (x.value)</td>
<%next
rs.movenext %>
</tr>
<% loop
rs.close
conn.close %>
</table>
</body>
</html>