Classic ASP - strange problem.

G

Gary

I am trying to do a simple "less than" conditional statement, and hitting a
brick wall if I use a database element with it.

This DOES work:
<%
if Request.QueryString("PC") < 10 then Response.Write("less than ten") else
Response.Write("more than or equal to ten") End if
%>


This DOES NOT work:
<%
if Request.QueryString("PC") < Record.Fields.Item("count(*)").Value then
Response.Write("less than COUNT") else Response.Write("less than or equal to
count") End if
%>

The only difference is that in the first example a number is used as the
condition. in the second example, I have counted the number of rows in a
table, and I want to use that number as the condition. The SQL select is:
SELECT count(*), EnquiryDate
FROM lfmasterleads.partner_enquiries
WHERE EnquiryDate = CURRENT_DATE() GROUP BY EnquiryDate

Any help greatly appreciated!

Darren.
 
S

Steven Burn

Why not use something like;

<%
Dim valCount
valCount = Record.Fields.Item("count(*)").Value

If Request.QueryString("PC") < valCount Then
Response.Write("less than COUNT")
Else
Response.Write("less than or equal to count")
End if
%>

This way, your sticking the value into a variable, rather than loading it
dynamically (if that makes sense?)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
 
E

Evertjan.

Gary wrote on 16 feb 2004 in microsoft.public.inetserver.asp.general:
I am trying to do a simple "less than" conditional statement, and
hitting a brick wall if I use a database element with it.

This DOES work:
<%
if Request.QueryString("PC") < 10 then Response.Write("less than ten")
else Response.Write("more than or equal to ten") End if
%>


This DOES NOT work:
<%
if Request.QueryString("PC") < Record.Fields.Item("count(*)").Value
then Response.Write("less than COUNT") else Response.Write("less than
or equal to count") End if
%>

comparing a string to a number, a conversion of the fitst to a number is
attempted

comparing two strings, no atempt is made and the comparison is
aphanumeric.

<script language=vbs>

' prepare IE vbs pseudo ASP test environment
set response = document

Response.Write ("17" > 6) & "<br>" & vbCrLf
Response.Write ("17" > "6") & "<br>" & vbCrLf

</script>
 
J

John Blessing

Gary said:
I am trying to do a simple "less than" conditional statement, and hitting a
brick wall if I use a database element with it.

This DOES work:
<%
if Request.QueryString("PC") < 10 then Response.Write("less than ten") else
Response.Write("more than or equal to ten") End if
%>


This DOES NOT work:
<%
if Request.QueryString("PC") < Record.Fields.Item("count(*)").Value then
Response.Write("less than COUNT") else Response.Write("less than or equal to
count") End if
%>

The only difference is that in the first example a number is used as the
condition. in the second example, I have counted the number of rows in a
table, and I want to use that number as the condition. The SQL select is:
SELECT count(*), EnquiryDate
FROM lfmasterleads.partner_enquiries
WHERE EnquiryDate = CURRENT_DATE() GROUP BY EnquiryDate

Any help greatly appreciated!

Darren.

Make sure the comparison is numeric

lCount = Record.Fields(0).value

if val (Request.QueryString("PC") ) < lCount then ...

--
John Blessing

http://www.LbeHelpdesk.com - Help Desk software priced to suit all
businesses
http://www.free-helpdesk.com - Completely free help desk software !
http://www.lbetoolbox.com - Remove Duplicates from MS Outlook
 
S

Steven Burn

John's just made me realise where my suggestion has gone wrong.........

If Request.QueryString("PC") < valCount Then

Should actually be;

If val(Request.QueryString("PC")) < valCount Then

Otherwise it's treated as a string........ (cheers John, hehe)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
 
G

Gary

Hi,

Already tried that - same problem I am afraid.
Seems like the COUNT maybe isnt stored as a numeric variable?
Gary.
 
G

Gary

John? Whos john? :)
Dont see his reply!

Gary.
Steven Burn said:
John's just made me realise where my suggestion has gone wrong.........

If Request.QueryString("PC") < valCount Then

Should actually be;

If val(Request.QueryString("PC")) < valCount Then

Otherwise it's treated as a string........ (cheers John, hehe)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)


in
 
S

Steven Burn

Have you checked the DB properties for that field to see what they're being
stored as?

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
 
G

Gary

Hi John,

Thanks for the tip, should I be using this?:

<%
if val(Request.QueryString("PartnerCap")) <
val(Recordset1.Fields.Item("count(*)").Value) then Response.Write("true")
else Response.Write("false") End if
%>

I get this:
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'val'

Gary.
 
B

Blair Bonnett

Try the following SQL:

SELECT count(*) As RecordCount, EnquiryDate FROM
lfmasterleads.partner_enquiries WHERE EnquiryDate = CURRENT_DATE() GROUP
BY EnquiryDate;

Then:

<%
If Request.QueryString("PC") <
CInt(Record.Fields.Item("RecordCount").Value) Then
Response.Write("less than COUNT")
Else
Response.Write("more than or equal to count")
End if
%>

Hope this helps,
Blair
 
G

Gary

Thank you!!!!
Worked a treat. I had to add the "CInt" to the Request.QueryString, but
once I did that, worked a treat.

Thanks to everyone else for there help too.

Gary.
 
G

Gary

PS - What is "CInt" ?


Blair Bonnett said:
Try the following SQL:

SELECT count(*) As RecordCount, EnquiryDate FROM
lfmasterleads.partner_enquiries WHERE EnquiryDate = CURRENT_DATE() GROUP
BY EnquiryDate;

Then:

<%
If Request.QueryString("PC") <
CInt(Record.Fields.Item("RecordCount").Value) Then
Response.Write("less than COUNT")
Else
Response.Write("more than or equal to count")
End if
%>

Hope this helps,
Blair
 
J

Julian Roberts

You'll need to cast the querystring value as a number. eg

if cdbl(Request.QueryString("PC")) < 10
 
C

Chris Barber

CInt - Convert to Integer
CDbl - Convert to Double
CLng - Convert to Long
CStr - Convert to String

NB: You should ideally be doing:

If CLng(Request.QueryString.Item("PC")) = CLng(varCount) then....

Of course you can also check using IsNumeric():

Dim pvarQSValue
pvarQSValue = Request.QueryString.Item("PC")
If IsNumeric(pvarQSValue) Then
If CLng(pvarQSValue) < varCount Then

End If
End If

The above is my construct of choice since the querystring values are read
only once (into a local variable). After that I sanity check it and then
process it. This three step process is important in ASP since what you don't
want is a single page to kill your website.

My advice: Always sanity check values that are passed to you (eg.
Request.QueryString and Response.Form) - this also (to some extent) includes
recordset values that may be null.

Hope this helps.

Chris.

PS - What is "CInt" ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,786
Messages
2,569,626
Members
45,328
Latest member
66Teonna9

Latest Threads

Top