how can i reslove [Microsoft][ODBC SQL Server Driver]Timeout expired

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • syedshaffee
    New Member
    • Jan 2012
    • 91

    how can i reslove [Microsoft][ODBC SQL Server Driver]Timeout expired

    I have web page while redirecting to the web page I receive this error Microsoft OLE DB Provider for ODBC Drivers (0x80040E31)
    [Microsoft][ODBC SQL Server Driver]Timeout expired
    I have a primary key in my table and when hit refresh the page is displayed here is the below code
    can some please help me on this
    Code:
    <%@ LANGUAGE="VBSCRIPT" %>
    <!--#INCLUDE FILE="../include/Constants.asp"   -->
    <!--#INCLUDE FILE="../include/commoninc_restrict.asp"-->
    
    <%varLocale = SetLocale(3081)%>
    <%strRootFolder = session("strRootFolder")%>
    <%
        TotalContracts = 0
        rentalQuarterlytotal = 0
    	Quarterlycount = 0
        Monthlycount = 0 
        Yearlycount = 0   
        HalfYearlycount = 0
    			sql = "SELECT distinct Staff.Staff_Name," & _
    		        " Staff.Staff_phone," & _
    		        " Staff.Staff_fax," & _
    		        " Staff.Staff_cell," & _
    		        " Staff.Staff_email" & _
    		        " from Staff inner join " & _
    		        " Customer_Detail on Staff.Staff_id = Customer_Detail.Customer_Staff_id " & _
    		        " where Customer_Detail.Customer_id = " & Session(CUSTOMER_ID)
    
    		Set objRIMSConn = Server.CreateObject("ADODB.Connection")
    		objRIMSConn.Open RIMS_CONNECT
    
    		Set rstStaffContact = Server.CreateObject("ADODB.Recordset")
    		rstStaffContact.Open sql, objRIMSConn, adOpenKeyset, adLockOptimistic
    
    		Set Session("rstStaffContact") = rstStaffContact		' Store for fast retrieval later on.
    
    	' get funder details
    	' if Session("rstStaffContact") is nothing then
    		sql = "SELECT Customer_Funder.Customer_Funder_AdjActual_date," & _
    		        " Customer_Funder.Customer_Funder_AdjActual," & _
    		        " Customer_Funder.Customer_Funder_Expiry " & _
    		        " from Customer_Funder " & _
    		        " where Customer_Funder.Customer_id = " & Session(CUSTOMER_ID) & _
    		        " and Customer_Funder.Customer_Funder_Expiry = " & _
    		        " (select min(Customer_Funder.Customer_Funder_Expiry)" & _
    		        " from Customer_Funder " & _
    		        " where Customer_Funder.Customer_id = " & Session(CUSTOMER_ID) & ")"
    
    		'Set objRIMSConn = Server.CreateObject("ADODB.Connection")
    		'objRIMSConn.Open RIMS_CONNECT
    
    		Set rstCustFunder = Server.CreateObject("ADODB.Recordset")
    		rstCustFunder.Open sql, objRIMSConn, adOpenKeyset, adLockOptimistic
    
    		Set Session("rstCustFunder") = rstCustFunder		' Store for fast retrieval later on.
    
    ' check if already have CustomerNotice
    ' if Session("CustomerNotice") is nothing then
    			sql = "SELECT Customer_Detail.CustomerNotice" & _
    		        " from Customer_Detail " & _
    		        " where Customer_Detail.Customer_id = " & Session(CUSTOMER_ID)
    
    		Set objRIMSConn = Server.CreateObject("ADODB.Connection")
    		objRIMSConn.Open RIMS_CONNECT
    
    		Set rstCustomerNotice = Server.CreateObject("ADODB.Recordset")
    		rstCustomerNotice.Open sql, objRIMSConn, adOpenKeyset, adLockOptimistic
    
    		Set Session("CustomerNotice") = rstCustomerNotice("CustomerNotice")		' Store for fast retrieval later on.
    '	end if
    
    	' check if already have Customer Contact details
    	' if Session("rstCustContact") is nothing then
    			sql = "SELECT distinct Customer_Contact.Contact_Name," & _
    		        " Customer_Contact.Contact_DDI," & _
    		        " Customer_Contact.Contact_fax," & _
    		        " Customer_Contact.Contact_mobile," & _
    		        " Customer_Contact.Contact_email," & _
    		        " Customer_Contact.Contact_address," & _
    		        " Customer_Contact.Contact_suburb," & _
    		        " Customer_Contact.Contact_city," & _
    		        " Customer_Contact.Contact_stateid," & _
    		        " Customer_Contact.Contact_postcode" & _
    		        " from Customer_Contact " &_
    		        " where Customer_Contact.Contact_Customer_id = " & Session(CUSTOMER_ID) &_
    		        " AND Customer_contact.Contact_Primary = 1 "
    
    
    		Set objRIMSConn = Server.CreateObject("ADODB.Connection")
    		objRIMSConn.Open RIMS_CONNECT
    
    		Set rstCustContact = Server.CreateObject("ADODB.Recordset")
    		rstCustContact.Open sql, objRIMSConn, adOpenKeyset, adLockOptimistic
    
    		Set Session("rstCustContact") = rstCustContact		' Store for fast retrieval later on.
    '	else
    		' Contact information already exists, retrieve it from the session object.
    '		Set rstCustContact = Session("rstCustContact")
    '	end if
    
    ' Process any sort requests.
    	If not(IsEmpty(Request("ContListSortItem"))) AND (Request("ContListSortItem") <> Session("ContListSortItem")) then
    		set Session("rstContract") = nothing
    		Session("ContListSortItem") = Request("ContListSortItem")
    	end if
    
    
    sql = "SELECT  " & _ 
    		    " Contract_detail.Contract_no, Contract_detail.ContractStatusID, " & _ 
    		    " Contract_detail.Contract_commence_date, " & _ 
    		    " Contract_detail.Contract_expiry_date, " & _ 
    		    " Contract_detail.Contract_rental, " & _ 
    		    " Contract_detail.Contract_assetmgmt, " & _ 
    		    " Contract_detail.Contract_term, " & _ 
    		    " Contract_detail.Contract_frequency, " & _ 
    		    " Contract_detail.Contract_disc_date, " & _ 
    		    " Contract_detail.Contract_disc_rec, " & _ 
    		    " Contract_detail.Contract_bank_settlement, " & _ 
    		    " SUM(isnull(Asset_Detail.Asset_purchase_price,0)) " & _ 
    		    " AS Contract_asset_value " & _
    		" FROM Contract_detail LEFT OUTER JOIN " & _
    		    " Asset_Detail ON " & _ 
    		    " Contract_detail.Contract_no = Asset_Detail.Asset_contract_no LEFT " & _
    		     " OUTER JOIN " & _
    		    " ContractRewriteHistory ON " & _ 
    		    " Contract_detail.Contract_no = ContractRewriteHistory.ContractNo " & _
    		     " LEFT OUTER JOIN " & _
    		    " Contract_detail New_Contract_Detail ON " & _ 
    		    " ContractRewriteHistory.ContractNewNo = New_Contract_Detail.Contract_no " & _
    		" WHERE Contract_detail.Contract_customer_id = " & Session(CUSTOMER_ID) & " " & _
    			" AND isnull(Contract_detail.Contract_Expired,0) = 0 AND " & _ 
    		    " isnull(Contract_detail.ContractStatusID,0) <> 5 AND " & _
    		    " ((isnull(Contract_detail.Contract_Rewritten, 0) = 0 OR isnull(New_Contract_Detail.Contract_bank_settlement, 0) = 0)) "
    
       		    if session("presettlement") = 0 then 
    				sql = sql & " AND Contract_detail.Contract_bank_settlement > 0 "  
    		    end if
    
    sql = sql &_
    		" GROUP BY Contract_detail.Contract_no, " & _
    		    " Contract_detail.ContractStatusID, " & _ 
    		    " Contract_detail.Contract_commence_date, " & _ 
    		    " Contract_detail.Contract_expiry_date, " & _ 
    		    " Contract_detail.Contract_rental, " & _ 
    		    " Contract_detail.Contract_assetmgmt, " & _ 
    		    " Contract_detail.Contract_term, " & _ 
    		    " Contract_detail.Contract_frequency, " & _ 
    		    " Contract_detail.Contract_disc_date, " & _ 
    		    " Contract_detail.Contract_disc_rec, " & _ 
    		    " Contract_detail.Contract_bank_settlement " & _
    		" HAVING " & _
    		    " (Contract_Detail.ContractStatusID IS NULL) OR " & _
    		    " (Contract_detail.ContractStatusID = 1) OR " & _
    		    " (Contract_detail.ContractStatusID = 2) OR " & _
     		    " (Contract_detail.ContractStatusID = 3 AND SUM(isnull(Asset_Detail.Asset_purchase_price,0)) <> 0) OR " & _
    		    " (Contract_detail.ContractStatusID = 4 AND Contract_detail.Contract_expiry_date > GETDATE()) OR " & _
    		    " (Contract_detail.ContractStatusID = 6) OR " & _
    		    " (Contract_detail.ContractStatusID = 7 AND " & _
    		    "	(SUM(isnull(Asset_Detail.Asset_purchase_price,0)) <> 0 OR Contract_detail.Contract_expiry_date > GETDATE()))"
    			   
    		if IsEmpty(Session("ContListSortItem")) OR (Session("ContListSortItem") = "") then
    			Session("ContListSortItem") = " right(Contract_Detail.Contract_no,4) asc"
    		end if
    
    		sql = sql & " ORDER BY " & Session("ContListSortItem")
    
    		Set rstContract = Server.CreateObject("ADODB.Recordset")
    		rstContract.Open sql, objRIMSConn, adOpenKeyset, adLockOptimistic
    		rstContract.PageSize = CONTRACTLIST_LIST_PAGE_SIZE		' Number of records to display per page.
    		Set Session("rstContract") = rstContract		' Store for fast retrieval later on.
    		Session("ContPage") = 1													' Start on the first page.
    	'else
    		' Contract information already exists, retrieve it from the session object.
    		Set rstContract = Session("rstContract")
    	'end if
    
    	' Determine whether there is no data in the recordset at this stage. Must check for BOF
    	' as well as we could be on the last page of the data, and in this case EOF would be true.
    	bolNoData = rstContract.EOF and rstContract.BOF
    	
    	' Process any paging move requests.
    	Select Case Trim(Request("PagingMove"))
    		Case "Requery"
    			rstContract.Requery
    		Case "<"
    			If Session("ContPage") > 1 Then
    				Session("ContPage") = Session("ContPage") - 1
    			End If
    		Case "<<"
    			Session("ContPage") = 1
    		Case ">"
    			if Session("ContPage") < rstContract.PageCount then
    				Session("ContPage") = Session("ContPage") + 1
    			end if
    		Case ">>"
    			Session("ContPage") = rstContract.PageCount
    	End Select
    
    	on Error resume next
    	rstContract.AbsolutePage = Session("ContPage")
    	Contract_asset_value=rstcontract("Contract_asset_value")
    	on error goto 0
    %>
    <%
    sql = "SELECT ControlValue " & _
    " from ControlData where argument = 'GST'"
    Set rstVat = Server.CreateObject("ADODB.Recordset")
    rstVat.Open sql, objRIMSConn, adOpenKeyset, adLockOptimistic
    
    sql = "SELECT ControlValue " & _
    " from ControlData where argument = 'Country'"
    Set rstVatt = Server.CreateObject("ADODB.Recordset")
    rstVatt.Open sql, objRIMSConn, adOpenKeyset, adLockOptimistic
    
    
    
    
    Ccountry = rstVatt("ControlValue")
    if Ccountry = "SA" then
    CountryCurrency = "R"
    session("CountryCurrency") = "R"
    end if
    if Ccountry = "NZ" then
    CountryCurrency = "$"
    session("CountryCurrency") = "$"
    end if
    if Ccountry = "AU" then
    CountryCurrency = "$"
    session("CountryCurrency") = "$"
    end if
    if Ccountry = "IN" then
    CountryCurrency = "Rs."
    session("CountryCurrency") = "Rs."
    end if
    
    
    
    
        TotalClientRentalValue=0
    	PaymentFrequency=0
    	TotalContracts=0
    	Do While Not rstContract.EOF
    		TotalContracts = TotalContracts + 1
    		TotalClientAssetValue = TotalClientAssetValue + NZ(rstContract("Contract_Asset_Value"),0)
    		if rstContract("Contract_frequency") = 90 then
    			Quarterlycount = Quarterlycount + 1
    			PaymentFrequency = "Quarterly"
    			ContractMonths = 3
    		elseif rstContract("Contract_frequency") = 30 then
    			Monthlycount = Monthlycount + 1
    			PaymentFrequency = "Monthly"
    			ContractMonths = 1
    		elseif rstContract("Contract_frequency") = 180 then
    			HalfYearlycount = HalfYearlycount + 1
    			PaymentFrequency = "Half Yearly"
    			ContractMonths = 6
    		elseif rstContract("Contract_frequency") = 360 then
    			Yearlycount = Yearlycount + 1
    			PaymentFrequency = "Yearly"
    			ContractMonths = 12
    		else
    			PaymentFrequency = (rstContract("Contract_frequency")) & "days"
    			ContractMonths = 360 / rstContract("Contract_frequency")
    		end if
    
    		rstContract.MoveNext
    	Loop
    	
    	
    on Error resume next
    	rstContract.AbsolutePage = 1
    	on error goto 0
    
    %>
    <SCRIPT LANGUAGE='JavaScript'>
    <!-- hide from old browsers
    
    	function order_by(column_order)
    		{
    		document.sortform.ContListSortItem.value=column_order;
    		document.sortform.submit()
    		}
    
    	function first_page()
    		{
    		document.paging.PagingMove.value="first";
    		document.paging.submit()
    		}
    	function prev_page()
    		{
    		document.paging.PagingMove.value="prev";
    		document.paging.submit()
    		}
    	function next_page()
    		{
    		document.paging.PagingMove.value="next";
    		document.paging.submit()
    		}
    	function last_page()
    		{
    		document.paging.PagingMove.value="last";
    		document.paging.submit()
    		}
    	function refresh_page()
    		{
    		document.paging.PagingMove.value="requery";
    		document.paging.submit()
    
    		}
    
    // end of javascript -->
    </SCRIPT>
    <!--#INCLUDE FILE="..\Include\header.asp"-->
    <% If Session(ALLOW_LIFECYCLE) then %>
    <title>Lifecycle Management Contracts</title>
    <% Else %>
    <title>Contract Management Contracts</title>
    <% End if %>
    <% Session("active_nav")="Contracts" %>
    <link rel="stylesheet" href="../Contract/stylemain.css">
    </head>
    <BODY marginwidth="0" marginheight="0" leftmargin="0" topmargin="0" BGCOLOR="#FFFFFF">
    <TABLE border="0" cellPadding="0" cellSpacing="0" width="100%" height="135">
    <TBODY>
    <TR>
    <TD align="center" vAlign="top" width="166" height="130">
    <img src="http://bytes.com/images/nav/logo_b.gif" width="166" border="0" height="135"></TD>
    <TD bgcolor="white" width="100%" align="center" valign="top" height="130">
    <table border="0" cellpadding="0" cellspacing="0" align="center">
    <tbody>
    <tr>
    <td bgcolor="silver" width="2%" height="111">
    &nbsp;
    </td>
    <td bgcolor="silver" width="51%" valign="top" height="111" align="center">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td colspan="3" align="center">
    &nbsp;
    </td>
    </tr>
    <tr>
    <td width="10" valign="top" align="right">
    </td>
    <td width="646" bgcolor="silver" valign="top" align=center>
    	<table border="0" cellpadding="0" cellspacing="0" class="clsArchiveTD">
    		<tr>
    			<td colspan=3 align=center>
    				<font face="Verdana, Arial, Helvetica, sans-serif"><b><font color="#ffffff">
    					Contract Summary
    					<%'=session("privileges")%>
    				</font></b></font>
    			</td>
    		</tr>
    		<tr>
    			<td width=160>
    				<font face="Verdana, Arial, Helvetica, sans-serif">
    					Total asset value:
    				</font>
    			</td>
    			<td width=15>
    				<font face="Verdana, Arial, Helvetica, sans-serif">
    					<%=CountryCurrency%> 
    				</font>
    			</td>
    			<td align=right>
    				<font face="Verdana, Arial, Helvetica, sans-serif">
    					<%= Formatnumber(TotalClientAssetValue)%>
    				</font>
    			</td>
    		</tr>
    		<tr>
    			<td>
    				<font face="Verdana, Arial, Helvetica, sans-serif">
    					<%'-----get the heading from the java at the bottom%>
    					Total rental
    				</font>
    			</td>
    			<td>
    				<font face="Verdana, Arial, Helvetica, sans-serif" size="1">
    					<%=CountryCurrency%>
    				</font>
    			</td>
    			<td align=right> 
    				<%'-----get the total from the java at the bottom%>
    				<font face="Verdana, Arial, Helvetica, sans-serif" size="1">
    					<div id="rrental" name="rrental">
    					</div>
    				</font>
    			</td>
    		</tr>
    		<tr>
    			<td>
    				<font face="Verdana, Arial, Helvetica, sans-serif">
    					Number of contracts:
    				</font>
    			</td>
    			<td colspan=2>
    				<font face="Verdana, Arial, Helvetica, sans-serif" size="1">
    					<%=TotalContracts%>
    				</font>
    			</td>
    		</tr>
    		<tr>
    			<td>
    				<font face="Verdana, Arial, Helvetica, sans-serif">
    					Notice period:
    				</font>
    			</td>
    			<td colspan=2>
    				<font face="Verdana, Arial, Helvetica, sans-serif">
    					<%=Session("CustomerNotice")%> days
    				</font>
    			</td
    		</tr>
    	</table>
    
    </td>
    <td width="27" valign="top" align="left">
    </td>
    </tr>
    <tr>
    <td colspan="3" align="center">
    <img src="http://bytes.com/submit/images/transparent.gif" width="2" height="2" border="0">
    </td>
    </tr>
    </table>
    </td>
    <td bgcolor="silver" width="1%" valign="top" height="111">
    &nbsp;
    </td>
    <td bgcolor="silver" width="46%" height="111" valign="top" align="center">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td colspan="3" align="center">
    &nbsp;
    </td>
    </tr>
    <tr>
    <td width="5%" align="right" valign="top">
    </td>
    <td width="90%" valign="top">
    <table border="0" cellpadding="0" cellspacing="0" width="100%" class="SmallText">
    <tr align="center">
    <th align="left" nowrap width="100%" colspan="2">
    <font face="Verdana, Arial, Helvetica, sans-serif"><b><font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;To Contact Us</font></b></font>
    </th>
    </tr>
    <tbody>
    <tr>
    <td width="50">
    <font face="Verdana, Arial, Helvetica, sans-serif">&nbsp;Name:</font>
    </td>
    <td>
    <font face="Verdana, Arial, Helvetica, sans-serif">
    <% on error resume next
                            name = rstStaffContact("Staff_Name")
                            pos = instr(1,rstStaffContact("Staff_Name"),",")
                            if pos <> 0 then
    							'name = right(rstStaffContact("Staff_Name"),len(rstStaffContact("Staff_Name"))-pos) + " " + left(rstStaffContact("Staff_Name"),pos - 1)  						       					       
    						else
    							name = rstStaffContact("Staff_Name")
                            end if
    %>
    <%= name %>
    </font>
    </td>
    </tr>
    <tr>
    <td width="50">
    <font face="Verdana, Arial, Helvetica, sans-serif">&nbsp;Phone:</font>
    </td>
    <%if isnull((rstStaffContact("Staff_phone"))) then
    						staff_phone = "+91 22 6761 6400" 
    						else 
    						staff_phone = rstStaffContact("Staff_phone")
                          end if
                          
                          %>
    <td>
    <font face="Verdana, Arial, Helvetica, sans-serif">
    <%= staff_phone %>
    </font>
    </td>
    </tr>
    <tr>
    <td width="50">
    <font face="Verdana, Arial, Helvetica, sans-serif">&nbsp;Fax:</font>
    </td>
    <%if isnull((rstStaffContact("Staff_fax"))) then
    						staff_fax = "+91 22 6695 0590" 
    						else 
    						staff_fax = rstStaffContact("Staff_fax")
                          end if
                          
                          %>
    <td>
    <font face="Verdana, Arial, Helvetica, sans-serif">
    <%= staff_fax %>
    </font>
    </td>
    </tr>
    <tr>
    <td width="50">
    <font face="Verdana, Arial, Helvetica, sans-serif">&nbsp;Mobile:</font>
    </td>
    <td>
    <font face="Verdana, Arial, Helvetica, sans-serif">
    <%= rstStaffContact("Staff_cell") %>
    </font>
    </td>
    </tr>
    <tr>
    <td width="50">
    <font face="Verdana, Arial, Helvetica, sans-serif">&nbsp;Email:</font>
    </td>
    <td>
    <font face="Verdana, Arial, Helvetica, sans-serif"><a href="mailto:<%= rstStaffContact("staff_email")%>"><font face="Verdana, Arial, Helvetica, sans-serif" color="Navy">
    <b>
    <%= rstStaffContact("Staff_email")%>
    </b></font></a></font>
    </td>
    </tr>
    </tbody>
    </table>
    </td>
    <td width="5%" valign="top" align="left">
    </td>
    </tr>
    <tr>
    <td colspan="3" align="center">
    <img src="http://bytes.com/submit/images/transparent.gif" width="200" height="8" border="0">
    </td>
    </tr>
    </table>
    </td>
    </tr>
    <tr bgcolor="white" valign="top" align="right">
    <td colspan="4">
    <table bgcolor="#e5e5e5" cellpadding="0" cellspacing="0" border="0">
    <tr>
    <td height="20">
    <div align="right">
    <a href="javascript:window.print()"><font size="1" face="Verdana, Arial, Helvetica, sans-serif" color="#2C85B1"><b>Print</b></font></a> 
    | <a href="javascript:refresh_page()"><font size="1" face="Verdana, Arial, Helvetica, sans-serif" color="#2C85B1"><b>Refresh</b></font></a>
    </div>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </tbody>
    </table>
    </TD>
    <TD width="1" align="left" valign="bottom" bgcolor="white" height="130">
    <table width="100%" border="0" cellspacing="0" cellpadding="0" height="100">
    </table>
    </TD>
    </TR>
    </TBODY>
    </TABLE>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" height="82%">
    <tr>
    <td width="168" valign="top" height="100%">
    <table width="166" border="0" cellspacing="0" cellpadding="0" height="100%">
    <tr>
    <td width="166" height="100%" background="../../images/nav/new_b.jpg" valign="top">
    <br>
    <!-- navbar begin -->
    <!-- left navigation -->
    <!--#INCLUDE FILE="../include/inc_menu.asp"-->
    </td>
    </tr>
    </table>
     <form name="paging" action="../contract/contlist_contract2.asp" method="POST">
                <input type="hidden" name="PagingMove">
              </form>
    
    </td>
    <td valign="top" height="645">
    <form name="sortform" ACTION="../Contract/contlist_contract2.asp" METHOD="POST">
    <br>
    <br>
    <table width="50%" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td height="10" width="2%">
    &nbsp;
    </td>
    <td height="10" width="98%">
    <p>
    <font face="Arial" size="3" color="#808080"><strong>View your contracts</strong></font>
    </p>
    </td>
    </tr>
    </table>
    
    <p>
    <INPUT TYPE="hidden" NAME="ContListSortItem" value="">
    </p>
    </form>
    <table CELLPADDING="1" CELLSPACING="1" WIDTH="100%" border="0">
    <tr bgcolor="#B0C5D4">
    <td bgcolor="#bfd0df">
    <center>
    <font face="Verdana, Arial, Helvetica, sans-serif"><b><a href="Javascript:order_by(' right(contract_detail.Contract_no ,4) asc')"><img src="http://bytes.com/submit/images/up_arrow.gif" alt="Click to sort by Contract No in ascending order" align="middle" border="0" width="13" height="9"></a>
    <a href="Javascript:order_by('right(contract_detail.Contract_no,4) desc')"><img src="http://bytes.com/submit/images/down_arrow.gif" alt="Click to sort by Contract No in descending order" align="middle" border="0" width="13" height="9"></a>
    <br>
    <font color="#000000">Contract No</font> </b></font>
    </center>
    </td>
    <td bgcolor="#bfd0df">
    <center>
    <font face="Verdana, Arial, Helvetica, sans-serif"><b><a href="Javascript:order_by('Contract_Detail.Contract_Commence_Date asc')">
    <img src="http://bytes.com/submit/images/up_arrow.gif" alt="Click to sort by Start Date  in ascending order" align="middle" border="0" width="13" height="9"></a>
    <a href="Javascript:order_by('contract_detail.Contract_Commence_Date desc')"><img src="http://bytes.com/submit/images/down_arrow.gif" alt="Click to sort by Start Date  in descending order" align="middle" border="0" width="13" height="9"></a>
    <br>
    <font color="#000000">Start Date</font> </b></font>
    </center>
    </td>
    <td bgcolor="#bfd0df">
    <center>
    <font face="Verdana, Arial, Helvetica, sans-serif"><b><a href="Javascript:order_by('contract_detail.Contract_Expiry_Date asc')">
    <img src="http://bytes.com/submit/images/up_arrow.gif" alt="Click to sort by End Date in ascending order" align="middle" border="0" width="13" height="9"></a>
    <a href="Javascript:order_by('contract_detail.Contract_Expiry_Date desc')"><img src="http://bytes.com/submit/images/down_arrow.gif" alt="Click to sort by End Date in descending order" align="middle" border="0" width="13" height="9"></a>
    <br>
    <font color="#000000">End Date</font> </b></font>
    </center>
    </td>
    <td bgcolor="#bfd0df">
    <center>
    <font face="Verdana, Arial, Helvetica, sans-serif"><b><a href="Javascript:order_by('contract_detail.Contract_term asc')"><img src="http://bytes.com/submit/images/up_arrow.gif" alt="Click to sort by Term in ascending order" align="middle" border="0" width="13" height="9"></a>
    <a href="Javascript:order_by('contract_detail.Contract_term desc')"><img src="http://bytes.com/submit/images/down_arrow.gif" alt="Click to sort by Term in descending order" align="middle" border="0" width="13" height="9"></a>
    <br>
    <font color="#000000">Term</font></b> </font>
    </center>
    </td>
    <td bgcolor="#bfd0df">
    <center>
    <font face="Verdana, Arial, Helvetica, sans-serif"><b><a href="Javascript:order_by('contract_detail.Contract_asset_value asc')">
    <img src="http://bytes.com/submit/images/up_arrow.gif" alt="Click to sort by Value in ascending order" align="middle" border="0" width="13" height="9"></a>
    <a href="Javascript:order_by('contract_detail.Contract_asset_value desc')"><img src="http://bytes.com/submit/images/down_arrow.gif" alt="Click to sort by Value in descending order" align="middle" border="0" width="13" height="9"></a>
    <br>
    <font color="#000000">Asset Value</font> </b></font>
    </center>
    </td>
    <td bgcolor="#bfd0df">
    <center>
    <font face="Verdana, Arial, Helvetica, sans-serif"><b><a href="Javascript:order_by('contract_detail.Contract_rental asc')"><img src="http://bytes.com/submit/images/up_arrow.gif" alt="Click to sort by Rental in ascending order" align="middle" border="0" width="13" height="9"></a>
    <a href="Javascript:order_by('contract_detail.Contract_rental desc')"><img src="http://bytes.com/submit/images/down_arrow.gif" alt="Click to sort by Rental in descending order" align="middle" border="0" width="13" height="9"></a>
    <br>
    <font color="#000000">Rental</font> </b></font>
    </center>
    </td>
    <td bgcolor="#bfd0df">
    <center>
    <font face="Verdana, Arial, Helvetica, sans-serif"><b><a href="Javascript:order_by('contract_detail.Contract_frequency asc')"><img src="http://bytes.com/submit/images/up_arrow.gif" alt="Click to sort by Payment in ascending order" align="middle" border="0" width="13" height="9"></a>
    <a href="Javascript:order_by('contract_detail.Contract_frequency desc')"><img src="http://bytes.com/submit/images/down_arrow.gif" alt="Click to sort by Payment in descending order" align="middle" border="0" width="13" height="9"></a>
    <br>
    <font color="#000000">Payment</font> </b></font>
    </center>
    </td>
    </tr>
    <%if bolNoData then%>
    <tr>
    <td colspan="4">
    There are no contracts to display.
    </td>
    </tr>
    <%else
    	BgColour = BGColourA
    	intRecordsPrinted = 0
    	intRecordNo = ((Session("ContPage") - 1) * CONTRACTLIST_LIST_PAGE_SIZE) + 1
    	if not blnNoData then
            rstContract.MoveFirst 
    	    Do While Not rstContract.EOF
    		    if rstContract("Contract_frequency") = 90 then
    			    PaymentFrequency = "Quarterly"
    			    ContractMonths = 3
    		    elseif rstContract("Contract_frequency") = 30 then
    			    PaymentFrequency = "Monthly"
    			    ContractMonths = 1
    		    elseif rstContract("Contract_frequency") = 180 then
    			    PaymentFrequency = "Half Yearly"
    			    ContractMonths = 6
    		    elseif rstContract("Contract_frequency") = 360 then
    			    PaymentFrequency = "Yearly"
    			    ContractMonths = 12
    		    else
    			    PaymentFrequency = (rstContract("Contract_frequency")) & "days"
    			    ContractMonths = 360 / rstContract("Contract_frequency")
    		    end if
    
    		    SSQL = "SELECT isnull(cashflowdate,0) as cashflowdate,isnull(cashflowamount,0) as cashflowamount,isnull(cashflowfid,0) as cashflowfid,isnull(cashflowstampduty,0) as cashflowstampduty from contract_cashflow where " & _
    		    "cashflowcontractno ='" & RSTCONTRACT("CONTRACT_NO") & "' and cashflowdate between getdate() and dateadd(m, " & ContractMonths & ",getdate())"
        		
    		    Set rstCASHFLOW = Server.CreateObject("ADODB.Recordset")
    		    rstCASHFLOW.Open ssql, objRIMSConn, adOpenKeyset, adLockOptimistic
        				
    		    if not rstCASHFLOW.EOF then
    				    rental = rstCASHFLOW("cashflowamount") + rstCASHFLOW("cashflowfid") + rstCASHFLOW("cashflowstampduty") 
    		    else
    		        SSQL = "SELECT isnull(cashflowdate,0) as cashflowdate,isnull(cashflowamount,0) as cashflowamount,isnull(cashflowfid,0) as cashflowfid,isnull(cashflowstampduty,0) as cashflowstampduty from contract_cashflow where " & _
    		        "cashflowcontractno ='" & RSTCONTRACT("CONTRACT_NO") & "' and cashflowdate = (select max (cashflowdate) from contract_cashflow where cashflowcontractno ='" & RSTCONTRACT("CONTRACT_NO") & "' ) "
    		        'Response.Write ssql	
    		        Set rstCASHFLOW = Server.CreateObject("ADODB.Recordset")
    		        rstCASHFLOW.Open ssql, objRIMSConn, adOpenKeyset, adLockOptimistic
            		
    		        on error resume next 'Code by Dan to fix error
    		        rental = rstCASHFLOW("cashflowamount")
    		        rental = rental + rstCASHFLOW("cashflowfid")
    		        rental = rental + rstCASHFLOW("cashflowstampduty")
        	    end if
        		
                constatusid = rstContract("ContractStatusID")
                contractvaluest = rstContract("Contract_Asset_Value")
    		    if isnull(contractvaluest) then 
    			    contractvaluest = 0
    		    end if 
    
    		    TotalClientRentalValue=TotalClientRentalValue + rental
    		    rentalQuarterlytotal = rentalQuarterlytotal + rentalQuarterlytotall
        		
    		    If intRecordsPrinted = CONTRACTLIST_LIST_PAGE_SIZE then		' Printed all contracts in this page.
    			    exit do
    		    End If%>
    
    
        <tr bgcolor="<%=BgColour%>">
        <td ALIGN="left" VALIGN="top" nowrap bgcolor="#000080">
        <a href="contdetail_contract2.asp?Contract_no=<%=rstContract("contract_no")%>">
        <%=rstContract("Contract_no")%>
        &nbsp; </a>
        </td>
        <td align="center" valign="top" bgcolor="<%=BgColour%>">
        <% If rstContract("Contract_Commence_Date") Then %>
    	    <%= FormatDateTime(rstContract("Contract_Commence_Date"),vbShortDate) %>
        <% end if %>
        </td>
        <td align="center" valign="top" nowrap bgcolor="<%=BgColour%>">
        <% If rstContract("Contract_Expiry_Date") Then %>
        <%=FormatDateTime(rstContract("Contract_Expiry_Date"),vbShortDate) %>
        &nbsp;
        <% end if %>
        </td>
        <td align="right" valign="top" nowrap bgcolor="<%=BgColour%>">
        <%=rstContract("Contract_term") %>
        &nbsp; months
        </td>
        <%if rstContract("Contract_Asset_Value") <> "" then%>
        <td align="right" valign="top" nowrap bgcolor="<%=BgColour%>">
        <%=CountryCurrency%>
        <%=FormatNumber(rstContract("Contract_Asset_Value"),2) %>
        &nbsp;
        </td>
        <%else%>
        <td align="right" valign="top" nowrap bgcolor="<%=BgColour%>">
        <%=CountryCurrency%>
        <%=FormatNumber(0,2) %>
        &nbsp;
        </td>
        <%end if%>
        <td align="right" valign="top" nowrap bgcolor="<%=BgColour%>">
        <%=CountryCurrency%>
        <%=FormatNumber(rental,2)%>
        &nbsp;
        </td>
        <%
            if rstContract("Contract_frequency") = 90 then
    	        PaymentFrequency = "Quarterly"
            elseif rstContract("Contract_frequency") = 30 then
    	        PaymentFrequency = "Monthly"
            elseif rstContract("Contract_frequency") = 360 then
    	        PaymentFrequency = "Yearly"
            else
    	        PaymentFrequency = int(rstContract("Contract_frequency"))
            end if
    
        %>
        <td align="center" valign="top" nowrap bgcolor="<%=BgColour%>">
        <%=PaymentFrequency%>
        &nbsp;
        </td>
        </tr>
        <%
    			    if BgColour = BGColourA then
    				    BgColour = BGColourB
    			    else
    				    BgColour = BGColourA
    			    end if
    			    intRecordsPrinted = intRecordsPrinted + 1
    			    intRecordNo = intRecordNo + 1
        					
                %>
        <%
    		    rstContract.MoveNext
    	    Loop
        end if	    
    end if%>
    </table>
    </td>
    </tr>
    <% 
          %>
    </table>
    <%'ccm----this sends the topmenu the total and heading  Quarterly,montly or yearly%>
    <script>
    	
    	window.rrental.innerHTML  = '<%=formatnumber(TotalClientRentalValue,2)%>';
    	
    </script>
    <%'-------ccm%>
    <%
        'objRIMSConn.Close
        'Set objRIMSConn = nothing
    %>
Working...