By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,162 Members | 1,038 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,162 IT Pros & Developers. It's quick & easy.

classic asp function to utilize on the recordset

100+
P: 120
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
http://bytes.com/topic/sql-server/an...le#post3622154

please advise

thanks in advance
Omar.
Nov 8 '10 #1
Share this Question
Share on Google+
5 Replies


jhardman
Expert 2.5K+
P: 3,405
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"))
Jared
Nov 8 '10 #2

100+
P: 120
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
Omar.
Nov 8 '10 #3

jhardman
Expert 2.5K+
P: 3,405
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"

Jared
Nov 9 '10 #4

100+
P: 120
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...

Omar.
Nov 9 '10 #5

jhardman
Expert 2.5K+
P: 3,405
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.

Jared
Nov 9 '10 #6

Post your reply

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