Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 19th, 2008, 01:35 PM
Authorized User
 
Join Date: Jun 2006
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
Default ASP If Statement

I have the following ASP code that works fine, up to the IF statement. I'm trying to display an image based on the result of the MachineName variable.

I'm getting "incorrect syntax errors" where the IF statement begins.

Code:
set rsqdb = conn.Execute ("Select MachineName, KPName, Severity, " _
& " EventMSG + '; ' + AgentMsgShort as EventMessages, DateAdd(ss, LastOccurTime-3600, '1969-12-31T18:00:00.000') as OccurTime " _
& " From Event, EventDetail " _
& " Where Severity < 6 " _
& " AND Status = 0 " _
& " AND EventDetail.EventID = Event.EventID " _
& " AND AgentMsgShort <>  'NULL' " _
& " AND CAST(FLOOR(CAST(DATEADD(S,LastOccurTime, '1969-12-31T18:00:00.000') AS FLOAT)) AS DATETIME) >= (getdate() -1 ) " _
& " AND EventMSG NOT LIKE '%Work Queue Length%' " _
& " AND EventMSG NOT LIKE '%DRA Outbound%' " _
& " AND EventMSG NOT LIKE '%Report Creation Failed%' " _
& " AND EventMSG NOT LIKE '%NCOGateway%' " _
& " AND EventMSG NOT LIKE '%Diagnostic Console%' " _
& " AND EventMSG NOT LIKE '%Pdsk%' " _
& " AND EventMSG NOT LIKE '%EventLog does not exist%' " _
& " Order By OccurTime DESC " _
 
&" If Machinename = 'enpefr' then " _
&" <img src="map10.jpg"> " _
&" end if ")
Any help is appreciated!

Dale
 
Old December 19th, 2008, 08:55 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default Your issue...

Is that if part of your SQL query? I don't think it's supposed to be but that's what you are doing? your adding it to the end of your query. Try this:

Code:
<%
set rsqdb = conn.Execute ("Select MachineName, KPName, Severity, " _
& " EventMSG + '; ' + AgentMsgShort as EventMessages, DateAdd(ss, LastOccurTime-3600, '1969-12-31T18:00:00.000') as OccurTime " _
& " From Event, EventDetail " _
& " Where Severity < 6 " _
& " AND Status = 0 " _
& " AND EventDetail.EventID = Event.EventID " _
& " AND AgentMsgShort <>  'NULL' " _
& " AND CAST(FLOOR(CAST(DATEADD(S,LastOccurTime, '1969-12-31T18:00:00.000') AS FLOAT)) AS DATETIME) >= (getdate() -1 ) " _
& " AND EventMSG NOT LIKE '%Work Queue Length%' " _
& " AND EventMSG NOT LIKE '%DRA Outbound%' " _
& " AND EventMSG NOT LIKE '%Report Creation Failed%' " _
& " AND EventMSG NOT LIKE '%NCOGateway%' " _
& " AND EventMSG NOT LIKE '%Diagnostic Console%' " _
& " AND EventMSG NOT LIKE '%Pdsk%' " _
& " AND EventMSG NOT LIKE '%EventLog does not exist%' " _
& " Order By OccurTime DESC ")
 
If rsqdb("Machinename").ToString = "enpefr" then %>
<img src="map10.jpg">
<% end if %>
I'm a .net coder so forgive me if I used incorrect syntax but you should get the Idea....
__________________
Jason Hall

Follow me on Twitter @jhall2013
 
Old December 19th, 2008, 09:59 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

One thing in that bothers me:

You are doing:

AND CAST(FLOOR(CAST(DATEADD(S,LastOccurTime, '1969-12-31T18:00:00.000') AS FLOAT)) AS DATETIME) >= (getdate() -1 )

Sor from this I gather that your LastOccurTime values are stored in the DB as seconds since 1/1/1970 GMT. Standard Unix/Linux time, in other words.

I think I'd rather see you do that this way:

AND CONVERT(DATETIME, CONVERT(VARCHAR,DATEADD(s,LastOccurTime,'12/31/1969 18:00'),112),112) >= getDate()-1

Though either way should work just fine.

*EXCEPT*

Except the bigger problem is the meaning of getDate() -1. That does *NOT* mean "yesterday at midnight". That means "exactly 24 hours ago".

Since you are going to all the work to strip the time off of the date+time, you can be assured that your result will *NEVER* be equal to getDate()-1 except at exactly midnight. Is that what you intended?
 
Old December 22nd, 2008, 02:28 PM
Authorized User
 
Join Date: Jun 2006
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by alliancejhall View Post
Is that if part of your SQL query? I don't think it's supposed to be but that's what you are doing? your adding it to the end of your query. Try this:

Code:
If rsqdb("Machinename").ToString = "enpefr" then %>
<img src="map10.jpg">
<% end if %>
I'm a .net coder so forgive me if I used incorrect syntax but you should get the Idea....
Thanks for the suggestion, but I'm getting the following error now:

Object doesn't support this property or method: 'ToString'
 
Old December 22nd, 2008, 02:29 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default Then...

...Drop the .ToString from rsqdb("MachineName")
__________________
Jason Hall

Follow me on Twitter @jhall2013
 
Old December 27th, 2008, 06:50 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 198
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via MSN to itHighway
Default

Use Cstr() to convert "MachineName" value into string.

Quote:
If CStr(rsqdb("Machinename")) = "enpefr" then %>
<img src="map10.jpg">
<% end if %>
 
Old December 28th, 2008, 02:06 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Pardon me, but that's just silly.

What kind of field could rsqdb("Machinename") be *EXCEPT* a string????

It's not going to hurt to use CSTR( ), but it will be doing exactly nothing. Except a very minor wasting of time. (Nanoseconds.)
 
Old December 28th, 2008, 07:21 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 198
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via MSN to itHighway
Default

Quote:
Originally Posted by Old Pedant View Post
Pardon me, but that's just silly.

What kind of field could rsqdb("Machinename") be *EXCEPT* a string????

It's not going to hurt to use CSTR( ), but it will be doing exactly nothing. Except a very minor wasting of time. (Nanoseconds.)
:) I do not know what data type "MachineName" expects. The only reason I recommended CStr() is that, in original post "alliancejhall" is trying to convert rsqdb("Machinename") data type string.
 
Old December 28th, 2008, 05:17 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

The reason I assume it must be a string is because of the value that it is being compared to:
Code:
     If rsqdb("Machinename") = "enpefr" then
enpefr couldn't be anything but a text field in a database, so ADO (and VBS) will have already converted it to a string.

The original code did *NOT* use ToString( ).

Jason ("Alliance") added that because he is used to ADO.NET and such classes as the SQLDataReader, where all data fields are just converted to System.Object (that standard basic root class in the .NET framework) and so you *do* need to cast the Object to the correct actual data type. In VB.Net, you can do that via *either*
Code:
    MyDataReader(0).ToString( )
or
    CStr(MyDataReader(0))
or even
    String.Format("{0}", MyDataReader(0))
Anyway, the ToString( ) was bogus all along, just Jason/Alliance trying to use VB.NET code instead of VBS. That's all.

Again, your answer's not wrong, in the sense that CSTR() can't hurt. Just unnecessary. ADO and VBS do a pretty good job of converting SQL data types to the correct corresponding VBScript data types. The exception is the SQL DECIMAL data type, which is converted to the VARIANT vtDecimal type, which VBScript can *NOT* handle. So if you intend to do anything other than Response.Write such a type you indeed need to convert it to DOUBLE using CDBL( ). And now we are into exotica.
 
Old December 31st, 2008, 12:00 PM
Authorized User
 
Join Date: Jun 2006
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks for all the help guys. I do appreciate it.





Similar Threads
Thread Thread Starter Forum Replies Last Post
SELECT statement in ASP please help jennypretty Classic ASP Basics 15 December 3rd, 2008 01:03 AM
add this select statement to this asp antonyx Classic ASP Databases 2 February 20th, 2005 11:51 AM
sql server and asp if statement shoakat Classic ASP Databases 2 November 2nd, 2004 07:38 PM
DELETE statement with ASP.NET kaz VS.NET 2002/2003 1 December 9th, 2003 09:35 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.