#1
  1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Database drven function


    Hi,

    I am a writing a website and have come accross an issue writing a function (which I am new to) using a database record, if anyone could show me the way it would be greatly appreciated.

    here is the code that I have and it is creating a fault...

    Code:
    Set rsSummaryLabour = Server.CreateObject("ADODB.Recordset")
    strSummaryLabour = "SELECT SUM (billingRate) as labour FROM jobsStaff WHERE job = " & request.QueryString("ID") & ""
    rsSummaryLabour.Open strSummaryLabour, adoCon
    	
    Set rsSummaryLabourCost = Server.CreateObject("ADODB.Recordset")
    strSummaryLabourCost = "SELECT SUM (payRate) as labourCost FROM jobsStaff WHERE job = " & request.QueryString("ID") & ""
    rsSummaryLabourCost.Open strSummaryLabourCost, adoCon
    	
    function labourCost
    	labourCost = (rsSummaryLabour("billingRate") - rsSummaryLabour("payRate"))
    end function
    thanks in advance for any pointers.
  2. #2
  3. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,594
    Rep Power
    278
    you do not need function. You should do that calculation in query
    Code:
    sql = "select (billingRate - payRate) as labourCost FROM jobsStaff WHERE job = " & request.QueryString("ID") & ""
    GK
    __________________________________________________ _____
    if you found this post is useful click Give Rep button (bottom side on this reply ) and agree
  4. #3
  5. 0x800A0C93
    ASP Super Hero (2500 - 2999 posts)

    Join Date
    Jan 2009
    Location
    Ridin' through this world...
    Posts
    2,975
    Rep Power
    1310
    GK is correct. Do the calculation in the SQL.

    To make your function work, your SQL selects sum of payrate but then calls it labourcost. The other statement selects sum of billingrate but then calls it labour. A function like:

    labourCost = (rsSummaryLabour("labour") - rsSummaryLabour("labourcost"))

    would move you more in the correct direction.
    Brinkster- free development account. Not affiliated, but I sure like free. Brinkster.com
  6. #4
  7. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    Thanks people, I have used GK suggestion, sorry for the late reply and thanks been a busy day.
    I appreciate the rapid response and if I could give you credit I would.
    Thanks again.

Similar Threads

  1. Connecting my function to the database.
    By pmillio in forum .NET Development
    Replies: 3
    Last Post: November 28th, 2007, 06:05 AM
  2. Database Search Function
    By jonnygrim in forum ASP Development
    Replies: 1
    Last Post: May 3rd, 2006, 06:47 AM
  3. Database connection in a function
    By b-ram in forum ASP Development
    Replies: 5
    Last Post: April 26th, 2005, 06:08 AM
  4. Need help with date function and database.
    By Razuu in forum ASP Development
    Replies: 2
    Last Post: January 11th, 2004, 06:19 PM
  5. Replace Function from Database
    By Monkey in forum ASP Development
    Replies: 1
    Last Post: November 13th, 2003, 03:28 AM

IMN logo majestic logo threadwatch logo seochat tools logo