Skip to main content
Inspiring
April 24, 2008
Question

function within SELECT statement

  • April 24, 2008
  • 3 replies
  • 472 views
Help please...
How can I get the my custom RFCal function to work within this select statement??

My Error:
The value SUM((a2.act_rate + a2.act_gratuity) * ap2.actpac_quantity) cannot be converted to a number.

My Code:
SELECT outer select blah blah,
(SELECT #RFCal("SUM((a2.act_rate + a2.act_gratuity) * ap2.actpac_quantity)" + p2.pac_serviceFee, p2.pac_occupancy)#
FROM tablep2 p2 INNER JOIN tableap2 ap2 ON p2.pac_id = ap2.pac_id
INNER JOIN tablea2 a2 ON ap2.act_id = a2.act_id
WHERE p2.pac_id = p.pac_id) AS myTotal
FROM tablep p INNER JOIN tableap ap ON p.pac_id = ap.pac_id
INNER JOIN tablea a ON ap2.act_id = a.act_id
WHERE outer select blah blah
This topic has been closed for replies.

3 replies

Inspiring
April 27, 2008
You can use an order by clause on the function result column in a query of queries to sort it.

But I think you have a null value somewhere. How else could a sum not be a number?
Inspiring
April 24, 2008
Plus, if any of those fields are null, the math result will also be null. Given your error message, this is likely.
romeogqAuthor
Inspiring
April 24, 2008
Thanks for responding Dan.

Your option of running the function on the result via a cfloop is what I am currently doing... problem is I want to be able to sort the function result. So with that, what would be the simplest method?

I will test running an additional query of queries on the result.
Inspiring
April 24, 2008
The subquery in the select clause might be returning more than row. That's a problem.

I'm not sure you can run cf functions inside queries like this. As a workaround, run it with just the math part first. Then loop through the results and apply the function to that column.