Page 1 of 1

Query Aliases (Select As)

Posted: 20 Oct 2006, 06:24
by harkonen
Having an issue with a select statement:

var sql = "SELECT AVG(total) AS averageTotal FROM Table"
var queryRes = dbase.executeQuery(sql);
var tempRow = queryRes.get(0);
var theAverage = tempRow.getItem("averageTotal")

theAverage returns null.

I can do a select that returns 1 numeric result without any problem. However, I cannot do an aliased result set in any way I have tried.

Any suggestions or thoughts?

HK

Posted: 21 Oct 2006, 11:13
by Lapo
I didn't have time to test the problem yet but I can suggest a couple of tests:

1 -> trace the size of the returned array.

Code: Select all

trace(queryRes.size())
what does it say?

2-> Try calling the executeQuery method like this:

Code: Select all

_server.executeQuery(theSql, _server.QUERY_INT_KEYS)
This will return an array of rows, where each row is indexed by numbers starting from index 1.
So now you can get the value like this:

Code: Select all

var theAverage = tempRow.getItem(1)

Posted: 01 Mar 2007, 03:41
by jflowers45
just an fyi

i think it has to be

Code: Select all

 var theAverage = tempRow.getItem(0)