I have a access query as below :
select column_date, sum(qty1), sum(qty2), sum(qty3) from table1
where column_date = [enter date]
group by column_date
union all
select 'Total' as column_date, sum(qty1), sum(qty2), sum(qty3) from table1
where column_date = [enter date]
Now I have asp code as below :
<%
Dim enterdate = Request.Form("enterdate")
set conn=Server.CreateObject("ADODB.Connection")
conn.open "odbcdatasourcename"
set rs = Server.CreateObject("ADODB.recordset")
sql="abovequery '" & enterdate & "' "
rs.Open sql, conn
%>
<table border="1" width="100%">
<%If rs.EOF then
Response.write ("<center>" & "<b>" & "There is no records for
the selected dates" & "</b>" & "</center>")%>
<%Else%>
<tr>
<%for each x in rs.Fields
response.write("<th>" & x.name & "</th>")
next%>
</tr>
<%do while not rs.EOF%>
<tr>
<%for each x in rs.Fields%>
<td><%Response.Write(x.value)%></td>
<%next
rs.MoveNext%>
</tr>
<%loop%>
<%End if%>
<%rs.close
conn.close%>
As you can see I have written it should display message “There is no records for the selected dates” when there is no data for the selected date.
But it still displays only last row with “Total” every time there is no record i.e. second query with blank values. Is it possible to fix it?
And I want to make “bold” last row i.e. Total row when there is record in database for selected date. Is it possible too here? Thanks in advance
You have two queries and should run them as such, first the query to get the data and then the query to get the total. The query as it stands will always return one row with Total as the date.
This is true even when the table is completely empty. You can check this by creating a table with one column called ID and no rows.
It will return one row.