Setting Condition with IF Then in ASP/HTML

Author Message
bobbykay1969

  • Total Posts : 1
  • Scores: 0
  • Reward points : 0
  • Joined: 8/12/2010
  • Status: offline
Setting Condition with IF Then in ASP/HTML Thursday, August 12, 2010 12:47 AM (permalink)
0
I have an ASP page that displays dates...some of the dates are old and I want anything older the 21 days to be red. So I did this...
 
</td>
    <td>
     <%if DateDiff(day, DBView("dsc_update"), Now()) < 21 then%>
          document.write('<font color="red"><%response.write DBView("dsc_update")%></font>') 
                  else
          document.write('<font color="blue"><%response.write DBView("dsc_update")%></font>') 
                  end if%>
    </td>
    <td>
 
When I run it I get HTTP Error 500  when I remove the code and just leave  ><%response.write DBView("dsc_update")%>  the page will display.
 
Here is the whole page of code....
 
<%
strSpan = Request.Form("days")
strSort = Request.Form("sort")
strMachine = Request.Form("machine")
strDate = date - strSpan
strReportType = Request.Querystring("T")
ConStr = "Provider=SQLOLEDB;server=n;Initial Catalog=p;User ID=C;Password=g;"
If strmachine = "" then
 set objConn = Server.CreateObject("ADODB.Connection")
 objConn.ConnectionString=ConStr
 objConn.open
 
 set DBView2 = Server.CreateObject("ADODB.Recordset")
 DBView2.ActiveConnection = objconn
 DBView2.cursortype = 1
 
 strAddField = "0"
 select case strReportType
  case "C"
   strSQL = "SELECT lname, fname, Cube_Loc, assettag, model, dsc_update, av2_date,wsus_sync, cmgs, cdp_bu, assetid, reboot FROM tb_Assets WHERE status = 'currently in use' and timestamp > '" & date - 1 & "' and (dsc_update < '" & date - 21 & "' or dsc_update is null) and datediff(day, wsus_sync, reboot) < - 21"
  case "B"
   strSQL = "select * from tb_assets where status = 'currently in use' and assettag not in (select right(computername,9) from vw_cdp) and model like '%latitude%'"
  case "A"
   strSQL = "select * from tb_assets where assettag in (select distinct right(Computer_Name,9) from n2db002.cim.cim.aps_software as CS inner join n2db002.cim.cim.aps_file as CF on CS.app_id = CF.app_id inner join n2db002.cim.cim.aps_file_machine as CFM on CFM.fl_id = CF.fl_id inner join n2db002.cim.cim.machine as CM on CM.ref_id = CFM.ref_id where app_name = 'Windows NT' and CS.app_version in ('5.02 EN','2000 SP3 EN','2000 SP4 EN')) order by dsc_update desc"
  case "9"
   strSQL = "SELECT NT.bn_user_cre, Cube_Loc, lname, fname, assettag, model, dsc_update, av2_date, wsus_sync, cmgs, cdp_bu, assetid, reboot FROM tb_Assets INNER JOIN n2db018.qpv8.dbo.blocnote as NT on right(NT.bn_des,9) = tb_assets.assettag WHERE assettag in (select right(bn_des,9) from n2db018.qpv8.dbo.blocnote where bn_action = 'C' and bn_elem = 'pw' and bn_date_cre > getdate()-14 and bn_date_cre < getdate()) and bn_action = 'C' and bn_elem = 'pw' and bn_date_cre > getdate()-14 and bn_date_cre < getdate()"
   strAddField = "1"
  case "8"
   strSQL = "SELECT lname, fname, Cube_Loc, assettag, model, dsc_update,av2_date, wsus_sync, cmgs, cdp_bu, assetid,reboot,credant FROM tb_Assets WHERE status <> 'currently in use' and (dsc_update > '" & date - 21 & "' or cdp_bu > '" & date - 21& "' or wsus_sync > '" & date - 21 & "') order by Dsc_update asc"
  case "7"
  strSQL = "SELECT lname, fname,  Cube_Loc,assettag, model, dsc_update,av2_date,wsus_sync,cmgs, cdp_bu, assetid,reboot,credant from vw_av_outofdate where dsc_update is not null and dsc_update > getdate()-30 and (dsc_update - av_date) > 4 order by av_date"
  case "6"
   strSQL = "SELECT lname, fname, Cube_Loc, assettag, model, dsc_update,av2_date,wsus_sync, cmgs, cdp_bu, assetid, reboot,credant FROM tb_Assets WHERE status = 'currently in use' and timestamp > '" & date - 1 & "' and lname is null and exempt IS NULL"   
  case "5"
   strSQL = "SELECT lname, fname, Cube_Loc, assettag, model, dsc_update,av2_date,wsus_sync, cmgs, cdp_bu, assetid, reboot,credant FROM tb_Assets WHERE status = 'currently in use' AND Credant IS NOT NULL Order by Credant"
  case "4"
   strSQL = "SELECT lname, fname,  Cube_Loc,assettag, model, dsc_update,av2_date, wsus_sync, cmgs, cdp_bu, assetid, reboot,credant FROM tb_Assets WHERE status = 'currently in use' and timestamp > '" & date - 1 & "' and (wsus_sync < '" & date - 21 & "' or wsus_sync is null) and exempt IS NULL"
  case "3"
    strSQL = "SELECT lname, fname,  Cube_Loc,assettag, model, dsc_update,av2_date,wsus_sync,cmgs, cdp_bu, assetid,reboot,credant from vw_av_outofdate where dsc_update is not null and dsc_update > getdate()-30 and (dsc_update - av_date) > 4 order by av_date"
  case "3a"
  strSQL = "SELECT lname, fname,  Cube_Loc,assettag, model, dsc_update,av2_date,wsus_sync,cmgs, cdp_bu, assetid,reboot,credant from vw_av2_outofdate where dsc_update is not null and dsc_update > getdate()-30 and (dsc_update - av2_date) > 4 order by av2_date"
  case "2"
   strSQL = "SELECT lname, fname, Cube_Loc, assettag, model, dsc_update,av2_date, wsus_sync, cmgs, cdp_bu, assetid, reboot,credant FROM tb_Assets WHERE status = 'currently in use' and timestamp > '" & date - 1 & "'"
  case "2a"
  strSQL = "SELECT lname, fname,  Cube_Loc,assettag, model, dsc_update,av2_date, wsus_sync, cmgs, cdp_bu, assetid, reboot,credant FROM tb_Assets WHERE status = 'currently in use' AND Loaner = '1'"
    case "2b"
  strSQL = "SELECT lname, fname, Cube_Loc,assettag, model, dsc_update,av2_date, wsus_sync, cmgs, cdp_bu, assetid, reboot,credant FROM tb_Assets WHERE Status = 'currently in use' AND  VIP ='1'"
  case "1"
   strSQL = "SELECT lname, fname,  Cube_Loc,assettag, model, dsc_update,av2_date, wsus_sync, cmgs, cdp_bu, assetid, reboot,credant FROM tb_Assets WHERE status = 'currently in use' and timestamp > '" & date - 1 & "' and (dsc_update < '" & date - 21 & "' or dsc_update is null)Order by dsc_update asc"
  case else
   strSQL = "SELECT lname, fname, Cube_Loc,assettag, model, dsc_update,av2_date, wsus_sync, cmgs, cdp_bu, assetid, reboot,credant FROM tb_Assets WHERE status = 'currently in use' and timestamp > '" & date - 1 & "' and ((dsc_update > '" & strDate & "' and (av_date < '" & strDate & "' or av_date is null or (cdp_bu < '" & strDate & "' and model not like '%optiplex%') or wsus_sync < '" & strDate & "' or wsus_sync is null or cmgs = 0) or dsc_update < '" & strDate & "' or dsc_update is null)) order by " & strSort
 end select
 set DBView = Server.CreateObject("ADODB.Recordset")
 DBView.ActiveConnection = objconn
 DBView.cursortype = 1
 DBView.Source = strSQL
 DBView.Open
 
 %>
 <table border="1">
  <%select case strReportType
   case "C"%>
    <tr>
     <td colspan = "10">
      <%response.write DBView.Recordcount%> machines have not rebooted in 21 days.
     </td>
    </tr>
   <%case "B"%>
    <tr>
     <td colspan = "10">
      <%response.write DBView.Recordcount%> laptops that do not have CDP.
     </td>
    </tr>
   <%case "A"%>
    <tr>
     <td colspan = "10">
      <%response.write DBView.Recordcount%> Windows 2000 workstations.
     </td>
    </tr>   
   <%case "9"%>
    <tr>
     <td colspan = "10">
      <%response.write DBView.Recordcount%> workstation objects created in the last 14 days.
     </td>
    </tr>
   <%case "8"%>
    <tr>
     <td colspan = "10">
      <%response.write DBView.Recordcount%> machines marked not in use, with recent network activity.
     </td>
    </tr>
   <%case "6"%>
    <tr>
     <td colspan = "10">
      <%response.write DBView.Recordcount%> machines with no user information.
     </td>
    </tr>
   <%case "5"%>
    <tr>
     <td colspan = "10">
      <%response.write DBView.Recordcount%> machines with out Credant service installed.
     </td>
    </tr>
   <%case "4"%>
    <tr>
     <td colspan = "10">
      <%response.write DBView.Recordcount%> machines with out of date or no data on WSUS. This will include machines that have no inventory data.
     </td>
    </tr>
   <%case "3"%>
    <tr>
     <td colspan = "10">
      <%response.write DBView.Recordcount%> machines with out of date or no data on AV files. This will include machines that have no inventory data.
     </td>
    </tr>  
   <%case "3a"%>
    <tr>
     <td colspan = "10">
      <%response.write DBView.Recordcount%> machines with AV 8.5 files.
    </td>
    </tr>    
   <%case "2"%>
    <tr>
     <td colspan = "10">
      <%response.write DBView.Recordcount%> machines are marked currently in use.
     </td>
    </tr> 
      <%case "2a"%>
    <tr>
     <td colspan = "10">
      <%response.write DBView.Recordcount%> machines are marked currently in use - other.
     </td>
    </tr>
    <%case "2b"%>
    <tr>
     <td colspan = "10">
      <%response.write DBView.Recordcount%> machines are marked currently in use - VIPs.
     </td>
    </tr>
   <%case "1"%>
    <tr>
     <td colspan = "10">
      <%response.write DBView.Recordcount%> machines have out of date inventory information.
     </td>
    </tr>
   <%case else%>
    <tr>
     <td colspan ='10'>
      This report is based on a machine is marked on currently in use by Qualiparc and one of the following:<br/>
       -1) A machine has not been discovered in the last <%Response.Write strSpan%> days<br/>
       -2) A machine has been discovered in the last <%Response.Write strSpan%> days and has failed one or more of the following criteria:<br/>
        ---a) The antivirus definition date is over <%Response.Write strSpan%> days old<br/>
        ---b) The WSUS last sync time is over <%Response.Write strSpan%> days old<br/>
        ---c) The last CDP backup is over <%Response.Write strSpan%> days old<br/>
        ---d) The machine does not have Credant<br/>
      The list is sorted by <%Response.Write strsort%>
     </td>
    </tr>
    <tr>
     <td colspan = "10">
      <%response.write DBView.Recordcount%> meet the report criteria.
     </td>
    </tr>
  <%end select%>
<!-- <tr>
   <td colspan='10'>
    <%strLink="'summary_excel.asp?T=" & strReportType & ",D=" & strSpan & ",S=" & strSort & ",M=" & strMachine & "'"%>
    <a href=<%=strlink%>>Click here for this report in XLS format</a>
   </td>
  </tr>-->
  <tr>
   <td>
    Asset Tag
   </td>
   <td>
    Last Name
   </td>
   <td>
    First Name
   </td>
   <td>
    Cube_Loc
    </td>
   <td>
    Model   
   </td>
   <td>
    Last Discovey Date   
   </td>
   <td>
     Anti Virus 8.5
   </td>
   <td>
    Last WSUS Sync   
   </td> 
   <td>
    Last Reboot
   </td>
   <td>
    Credant   
      </td>
  </tr>
 
 <%if Not DBView.EOF Then
     While Not DBView.EOF
      strSQL = "SELECT * FROM tb_comments WHERE assetid = '" & DBView("assetid") & "'"
      DBView2.Source = strSQL
   DBView2.Open
   if DBView2.RecordCount <> 0 then
    strComm = DBView2.Recordcount
   else
    strComm = "0"
   end if
   DBview2.Close
     %>
   <tr>
    <td>
     <%response.write "<p><A style='TEXT-DECORATION: none' href='detail.asp?W=" & DBView("assettag") & "'>" & DBView("assettag") & "</a></p>"%>
    </td>
    <td>
     <%response.write DBView("lname")%>
    </td>
    <td>
     <%response.write DBView("fname")%>
    </td>
    <td>
    <%response.write DBVIEW ("Cube_Loc")%>
    </td>
    <td>
     <%response.write DBView("model")%>   
    </td>
    <td>
     <%if DateDiff(day, DBView("dsc_update"), Now()) < 21 then%>
          document.write('<font color="red"><%response.write DBView("dsc_update")%></font>') 
                  else
          document.write('<font color="blue"><%response.write DBView("dsc_update")%></font>') 
                  end if%>
    </td>
    <td>
       <%response.write DBView("av2_date")%>    
    </td>
    <td>
     <%response.write DBView("wsus_sync")%>   
    </td>
    <td>
     <%response.write DBView("reboot")%>   
    </td>
    <td>
     <%response.write DBView("credant")%>   
    </td>  
   </tr>
 </table>
         <%DBView.MoveNext
     wend
 End if
Else
  strURL = "http://support/pdsm/detail.asp?W=" & strmachine
  Response.Redirect strURL
 end if%>
<!--</body>-->-->
<body>
</body>
</html>
 
#1
    ebgreen

    • Total Posts : 8227
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    Re:Setting Condition with IF Then in ASP/HTML Thursday, August 12, 2010 2:02 AM (permalink)
    0
     <%if DateDiff(day, DBView("dsc_update"), Now()) < 21 then%>

    If day is a variable that you have defined somewhere, then your naming conventions need some work. If it is not a variable that you have defined somewhere, then you need to go back and read the documentation for the DateDiff function.
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9