How to Sum from query search result - asp-classic

I want to SUM from a query search result. I have a table called Students. I created a Search form to list students with scores from Jan or Feb, by date range. The results are different (two rows, four rows, so on) based on how many months I search. I created a Sum row at the bottom to count the total from that column for Jan or Feb. However, it doesn't work at all.
Can anyone help?
Here is my code:
<table>
<tr>
<td>Student Name</td>
<td>Jan</td>
<td>Feb</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td><%=oRs("Name")%></td>
<td <%=sRowStyle%>><%=oRs("Jan")%></td>
<td <%=sRowStyle%>><%=oRs("Feb")%></td>
</tr>
<tr>
<td colspan="3"><% total = total + CInt(oRs("Jan")) oRs.MoveNext WEND %>
</td>
<tr>
</tr>
</table>

It looks like you haven't defined where your recordset loop starts
Try this:
<% Dim CountJan, CountFeb
Do while not oRS.eof %>
<tr>
<td><%=oRs("Name")%></td>
<td <%=sRowStyle%>><%=oRs("Jan")%></td>
<td <%=sRowStyle%>><%=oRs("Feb")%></td>
</tr>
<% CountJan = CountJan + Cint(oRs("Jan"))
CountFeb = CountFeb + Cint(oRs("Feb"))
oRs.MoveNext
Loop
%>
<tr>
<td> </td>
<td><%=CountJan%></td>
<td><%=CountFeb%></td>
</tr>
You can use while and wend instead of do while not and loop, its a matter of personal preference

Related

Logic to reduce current to_date by one when new from_date arrives

I need a logic in pl/sql to reduce valid_to date field by one day than new from_date.
Example: my current from and to dates are :
From: Jan-18-2016
To: Dec-31-9999
When new from and to dates arrive:
New From: Feb-1-2016
New To: Dec-31-9999
I want my old to_date to become Jan_31-2016 (ie, (Feb-1-2016) -1)
Currently I'm facing multiple data issue since there would be two valid_to dates at same time.
Please help
I have created dummy table with following data:
<table>
<tr>
<th>PRODUCT</th>
<th>FROM_DATE</th>
<th>VALID_TO</th>
</tr>
<tr>
<td>ABC</td>
<td>18-Jan-2016</td>
<td>31-Dec-9999</td>
</tr>
<tr>
<td>ABC</td>
<td>01-Feb-2016</td>
<td>31-Dec-9999</td>
</tr>
<tr>
<td>DEF</td>
<td>01-Aug-2016</td>
<td>31-Dec-9999</td>
</tr>
<tr>
<td>DEF</td>
<td>01-Sep-2016</td>
<td>31-Dec-9999</td>
</tr>
<tr>
<td>GHI</td>
<td>01-Mar-2016</td>
<td>31-Dec-9999</td>
</tr>
</table>
The following block will update the date according to your requirement. Using LAG and LEAD function you can access more than one row without joining the same table. LAG is used to access the previous row and LEAD is used to access the next row.
BEGIN
FOR I IN (SELECT NVL(LEAD(T.FROM_DATE)
OVER(PARTITION BY T.PRODUCT ORDER BY T.FROM_DATE) - 1,
T.VALID_TO) NEW_VALID_TO,
PRODUCT,
FROM_DATE
FROM PRODUCT_TABLE T) LOOP
UPDATE PRODUCT_TABLE A
SET A.VALID_TO = I.NEW_VALID_TO
WHERE A.PRODUCT = I.PRODUCT
AND A.FROM_DATE = I.FROM_DATE;
COMMIT;
END LOOP;
END;
The output will be as shown below:
<table>
<tr>
<th>PRODUCT</th>
<th>FROM_DATE</th>
<th>VALID_TO</th>
</tr>
<tr>
<td>ABC</td>
<td>18-Jan-2016</td>
<td>31-Jan-2016</td>
</tr>
<tr>
<td>ABC</td>
<td>01-Feb-2016</td>
<td>31-Dec-9999</td>
</tr>
<tr>
<td>DEF</td>
<td>01-Aug-2016</td>
<td>31-Aug-2016</td>
</tr>
<tr>
<td>DEF</td>
<td>01-Sep-2016</td>
<td>31-Dec-9999</td>
</tr>
<tr>
<td>GHI</td>
<td>01-Mar-2016</td>
<td>31-Dec-9999</td>
</tr>
</table>

Splitting table with multiple columns into individual tables

I have a website with lots of tables that have 2-3 columns but I need to convert each column into its own table so they will stack up for the mobile site. I'm looking at a daunting amount of work at the moment.
Is there a way that I can split each column into its own table without doing all of it by hand? I'm working in code but would a WYSIWYG software allow me to do this perhaps? Or some other type of workaround?
<table class="dataTable">
<thead>
<tr>
<th>Hauptwerk</th>
<th>Brustwerk (expressive)</th>
<th>Pedal</th>
</tr>
</thead>
<tbody>
<tr>
<td>Prinzipal 8'</td>
<td>Gedackt 8'</td>
<td>Subbass 16'</td>
</tr>
<tr>
<td>Hohlflöte 8'</td>
<td>Rohrflöte 4'</td>
<td>Prinzipal 8'</td>
</tr>
<tr>
<td>Oktave 4'</td>
<td>Nazat 2-2/3'</td>
<td>Bourdon 8'</td>
</tr>
<tr>
<td>Flöte 2'</td>
<td>Prinzipal 2'</td>
<td>Oktave 4'</td>
</tr>
<tr>
<td>Mixtur IV</td>
<td>Terz 1-3/5'</td>
<td>Fagott 16'</td>
</tr>
<tr>
<td>Trompete 8'</td>
<td>Quinte 1-1/3'</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>Scharff III</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td class="italic">Tremulant</td>
<td> </td>
</tr>
</tbody>
</table>
I'm not sure which part of the CSS would be relevant, here is a sample page:
http://letourneauorgans.com/en/opus121.php

Loop based in variable value in asp classic

I have to output a table based on value of a variable. I have a unique block of table with variables. Depending on the view there should be a loop the re-read the table.
The variable could have the values Two or Three or both. I have to output the table with view One in all the cases.
Example #1:
Views = "Two, Three"
Output:
<table>
<tr>
<td>Table For View One</td>
</tr>
</table>
<table>
<tr>
<td>Table For View Two</td>
</tr>
</table>
<table>
<tr>
<td>Table For View Three</td>
</tr>
</table>
Example #2:
Views = "Two"
Output:
<table>
<tr>
<td>Table For View One</td>
</tr>
</table>
<table>
<tr>
<td>Table For View Two</td>
</tr>
</table>
Example #3:
Views = "Three"
Output:
<table>
<tr>
<td>Table For View One</td>
</tr>
</table>
<table>
<tr>
<td>Table For View Three</td>
</tr>
</table>
Tried to mix some While and For, without success.
<%
i=2
Do While i = 0
%>
<table>
<tr>
<td><% Response.Write i %></td>
</tr>
</table>
<%
i=i-1
Loop
%>
Try this:
<%
Dim Views : Views ="Two" 'Change this to check
Response.write "Initial View =" & Views & "<br/>"
'But "One" will always be printed
If InStr(Views,"One")=0 Then
'add if there is no "One" already
Views = Views & ",One"
End If
Response.write "New View =" & Views & "<br/>"
Dim ArrValues : ArrValues =Array("One","Two","Three")
Dim Counter
For Counter=0 to UBound(ArrValues)
If InStr(Views,ArrValues(Counter))<>0 Then
%>
<table>
<tr>
<td>Table For View <%=ArrValues(Counter)%></td>
</tr>
</table>
<%
'Response.write ArrValues(Counter) & "<br/>"
End If
Next
%>
I think something like this would work fine. I just use if else if. Also I compansated for the case that Views could equal "Two, Three" or "Three, Two".
<%if Views = "Two" then%>
<table>
<tr>
<td>Table For View One</td>
</tr>
</table>
<table>
<tr>
<td>Table For View Two</td>
</tr>
</table>
<%else if Views = "Three"%>
<table>
<tr>
<td>Table For View One</td>
</tr>
</table>
<table>
<tr>
<td>Table For View Three</td>
</tr>
</table>
<%else if Views = "Two, Three"%>
<table>
<tr>
<td>Table For View One</td>
</tr>
</table>
<table>
<tr>
<td>Table For View Two</td>
</tr>
</table>
<table>
<tr>
<td>Table For View Three</td>
</tr>
</table>
<%else if Views = "Three, Two"%>
<table>
<tr>
<td>Table For View One</td>
</tr>
</table>
<table>
<tr>
<td>Table For View Three</td>
</tr>
</table>
<table>
<tr>
<td>Table For View Two</td>
</tr>
</table>
<%end if%>
There are multiple ways to approach this but without changing your code to much, it can be done by splitting your Views variable into an Array using the comma , as a delimiter. Once you have the Array use a For loop to iterate through the Views and use a Select statement to return the correct view.
As you specified that Table One will always be included it has been left outside of the loop.
Something like this (not tested);
<%
Dim item, items
'Build the array from the Views comma separated string
Views = Split(Views, ",")
'Always include Table One
%>
<table>
<tr>
<td>Table For View One</td>
</tr>
</table>
<%
'Check we have an Array built from the Split().
If IsArray(Views) Then
'How many views have we requested?
items = UBound(Views)
For item = 0 To items
'What view are we current looking at in the loop?
Select Case LCase(Trim(Views(item) & ""))
Case "two"
%>
<table>
<tr>
<td>Table For View Two</td>
</tr>
</table>
<%
Case "three"
%>
<table>
<tr>
<td>Table For View Three</td>
</tr>
</table>
<%
End Select
Next
End If
%>
Depending on the complexity of your views you could break each table into it's own Sub procedure or one Sub procedure and call in place of the in-line table definitions. Something like below;
Sub ShowTable(view)
'Keep all in-line table definitions together.
Select Case Trim(LCase(view & ""))
Case "one"
%>
<table>
<tr>
<td>Table For View One</td>
</tr>
</table>
<%
Case "two"
%>
<table>
<tr>
<td>Table For View Two</td>
</tr>
</table>
<%
Case "three"
%>
<table>
<tr>
<td>Table For View Three</td>
</tr>
</table>
<%
End Select
End Sub
In the main loop you would added ShowTable() calls in place of any in-line table code, for example;
<%
Dim item, items
'Build the array from the Views comma separated string
Views = Split(Views, ",")
'Always include Table One
Call ShowTable("one")
'Check we have an Array built from the Split().
If IsArray(Views) Then
'How many views have we requested?
items = UBound(Views)
For item = 0 To items
'What view are we current looking at in the loop?
Call ShowTable(views(item))
Next
End If
%>
Your output will then look something like this (if you pass "Two, Three") for example;
<table>
<tr>
<td>Table For View One</td>
</tr>
</table>
<table>
<tr>
<td>Table For View Two</td>
</tr>
</table>
<table>
<tr>
<td>Table For View Three</td>
</tr>
</table>
Update based on OP feedback
If you don't want multiple tables (which is not clear from your question) then just remove the <table> and </table> in-line definitions (in the ShowTable() procedure), this will create the "guts" of your table (a series of table rows).
Then in the example code above just add <table> at the start and after the code </table>, which will encapsulate your dynamically generated table rows into one table.
<table>
<%
Dim item, items
'Build the array from the Views comma separated string
Views = Split(Views, ",")
'Always include Table One
Call ShowTable("one")
'Check we have an Array built from the Split().
If IsArray(Views) Then
'How many views have we requested?
items = UBound(Views)
For item = 0 To items
'What view are we current looking at in the loop?
Call ShowTable(views(item))
Next
End If
%>
</table>
Your output will then look something like this (if you pass "Two, Three") for example;
<table>
<tr>
<td>Table For View One</td>
</tr>
<tr>
<td>Table For View Two</td>
</tr>
<tr>
<td>Table For View Three</td>
</tr>
</table>

How to make the table 2 * 2 with rules in aspx page

Can I make the table with rules in my aspx page.
right now I am dispalying the page some thing like this.
Benefit Type : 000
Benfit Set: BCPCP
Converage Level : IND -Individual
Deductable Type : D-DED
Can I differnciate with the rules each and every row. like this
Benefit Type : 000
Benfit Set: BCPCP
Converage Level : IND -Individual
Deductable Type : D-DED
here is my Aspx code.. is there any way I can make like this?
<table>
<tr>
<td>
</td>
</tr>
You can just do a row with an hr in it like this: http://jsfiddle.net/WXSpD/
<table>
<tr>
<td>Benefit Type:</td>
<td>000</td>
</tr>
<tr>
<td colspan="2"><hr/></td>
</tr>
<tr>
<td>Benfit Set:</td>
<td>BCPCP</td>
</tr>
</table>
Your question is very hard to understand, but if you're just looking for a two-by-two table, can't you do it like this?:
<table>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
If there's something else you're looking for, can you clarify a little bit?

ASP.NET MVC View with embedded code displays html out of sequence

I have a view in ASP.NET MVC. It takes the model object and iterates over a list of strings and displays them in a table row, like so:
Details
<table>
<tbody>
<tr>
<th>Values in the database</th>
</tr>
<% foreach (string value in Model.lstDistinctValues)
{%>
<tr>
<%=value%>
<%} %>
</tr>
</tbody>
The problem is that the values appear ABOVE the header. So 'Values in the database' appears at the bottom, while the values are at the top.
Why would this be happening?
You need to add TD elements.
<table>
<tbody>
<tr>
<th>Values in the database</th>
</tr>
<% foreach (string value in Model.lstDistinctValues)
{%>
<tr>
<td><%=value%></td>
</tr>
<%} %>
</tbody>
</table>

Resources