January 4th, 2013, 01:50 AM
Database drven function
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...
thanks in advance for any pointers.
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
labourCost = (rsSummaryLabour("billingRate") - rsSummaryLabour("payRate"))
January 4th, 2013, 08:17 AM
you do not need function. You should do that calculation in query
sql = "select (billingRate - payRate) as labourCost FROM jobsStaff WHERE job = " & request.QueryString("ID") & ""
if you found this post is useful click Give Rep button (bottom side on this reply ) and agree
January 5th, 2013, 12:07 AM
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
January 5th, 2013, 03:33 AM
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.