Storing variables names in a database
Hi;
I'm storing some calculations in a database table and need to retrieve them and run them in a query, one of them needs to access the value of an argument passed to the function performing the query/calculation. Problem is I'm not sure how to evaluate the variable when it is retrieved - it's not getting processed.
Any ideas?
here is the functon:
<cffunction
name="fnShowliveSurcharge" access="public" output="true"
returntype="any" hint="makes a calculation based on a formulae" >
<cfargument name="avgCost" required="true" />
<cfquery name="qryGetAlloys" datasource="#variables.dsn#" result="qryGetAlloys_results" >
select * from nas_alloys;
</cfquery>
<cfquery name="qryGetGrades" datasource="#variables.dsn#" result="qryGetGrades_results" >
select * from nas_grades order by id;
</cfquery>
<cfloop query="qryGetGrades">
<cfloop query="qryGetAlloys">
<cfquery name="qryGetSurcharge" datasource="#variables.dsn#" result="qryGetSurcharge_results">
select
#qryGetAlloys.formulae# as myValue
from nas_alloys a left join nas_triggers t on t.alloyid = a.id
left join nas_astm astm on astm.alloyid = a.id
left join nas_estimatedprice ep on ep.alloyid = a.id
where astm.gradeid = '#qryGetGrades.Id#'
and a.id = '#qryGetAlloys.Id#';
</cfquery>
</cfloop>
</cfloop>
</cffunction>
the second line of the query is inserting
((#arguments.avgCost# - t.value) * (astm.astm/100) * 1.2)
from the nas_alloys table, however the query ends up looking like;
select ((#arguments.avgCost# - t.value) * (astm.astm/100) * 1.2) as myValue
from nas_alloys a left join nas_triggers t on t.alloyid = a.id left join nas_astm astm on astm.alloyid = a.id left join nas_estimatedprice ep on ep.alloyid = a.id where astm.gradeid = '1' and a.id = '1';
instead of:
select ((2.2289 - t.value) * (astm.astm/100) * 1.2) as myValue from nas_alloys a left join nas_triggers t on t.alloyid = a.id left join nas_astm astm on astm.alloyid = a.id left join nas_estimatedprice ep on ep.alloyid = a.id where astm.gradeid = '1' and a.id = '1';
Any thoughts on how to correct this?
-thanks
-sean
