471,108 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,108 software developers and data experts.

classic asp function to utilize on the recordset

120 100+
hi guys

i'm using sql server and classic asp. I'd like to know if there is a way to apply a 10% discount or any other calculation on to my sql table that contains prices via asp on the front end??

can this be done via a asp function upon recordset retrievel? something like this?..
Expand|Select|Wrap|Line Numbers
  1. Response.Write "£" & ASPFUNCTION(objRS("Triple_Redleaf_Price")) & "
sample data
Expand|Select|Wrap|Line Numbers
  1. ID Date_Band      Redleaf_Tour  Goldleaf_Tour Double_Accomodation Triple_Accomodation Single_Accomodation Child_Accomodation Double_Redleaf_Price Double_Goldleaf_Price Triple_Redleaf_Price Triple_Goldleaf_Price Single_Redleaf_Price Single_Goldleaf_Price Child_Redleaf_Price Child_Goldleaf_Price
  2. 1  May<br />2011  Redleaf       Goldleaf      Double              Triple              Single              Child(2-11 years)  489                  989                   479                  979                   539                  1039                  419                 909
I have been told it would be better to perform this function via asp front end rather than my sql statement

please advise

thanks in advance
Nov 8 '10 #1
5 3149
3,406 Expert 2GB
Yes, the function would be defined something like this:
Expand|Select|Wrap|Line Numbers
  1. function discount(listedValue)
  2.    Discount = 0.9 * listedValue
  3. End function
and the call would be just
Expand|Select|Wrap|Line Numbers
  1. response.write discount(objRS("red_leaf_price"))
Nov 8 '10 #2
120 100+
hi jared

your above suggestion worked great.

is it however possible to apply this function to all recordset calls as a shortcut as opposed to adding the discount function to every applicable recordset call?

ideally a function that checks if rs is an integer then apply discount otherwise ignore?

thanks in advance
Nov 8 '10 #3
3,406 Expert 2GB
Yes, I assume you don't need advice on looping or setting up an if statement. To check the field type, try objRS("fieldName").type - this returns an integer value. I don't remember any of the individual values, but that's what I use to say "if it's a type x then do y"

Nov 9 '10 #4
120 100+
I should be okay setting up an if loop statement.

im a bit confused as to what you mean though - do I add objRS("fieldName").type to the function?

is it not possible to avoid manually adding the function to all recordset calls and instead declaring the function once and it automatically filters through on all integer type data?

I am able to do this on the sql select statement using the cast function but it requires me to explicitly cast every applicable column. im looking for a more leaner way.

or is there an option to save the function as a stored proc and exec it from the db on to several tables?? just brainstorming here...

Nov 9 '10 #5
3,406 Expert 2GB
There have been several times that I have made a quick asp page to edit or add a record to a db. I typically make a form and loop through the fields putting one input in the form for each field in the db row. This usually looks like this:
Expand|Select|Wrap|Line Numbers
  1. for each x in objRS.fields
  2.    Response.write "<input type=""text"" name=" & chr(34) & x.name &  chr(34) & " value=" & chr(34) & objRS(x) & chr(34) & ">"
  3. Next
. With me so far? I often want a slightly different input for integer versus text fields. For example if I had a large text memo field I would want a textarea rather than a text input. In that case I put an if statement within the loop like this:
Expand|Select|Wrap|Line Numbers
  1. if x.type =4 then
  2.    Response.write "<textarea " 'etc
  3. Else
  4.    Response.write "<input " 'etc
  5. End if
does this make sense? This might not exactly answer your question, but this is how I would approach it.

Nov 9 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

18 posts views Thread by Darryl Kerkeslager | last post: by
7 posts views Thread by Christian Blackburn | last post: by
3 posts views Thread by Ted Ngo | last post: by
2 posts views Thread by fpennisi | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.