Does QueryToClass have numeric indexing?

Recommended Posts

I have an issue querying a large database where some column names on separate tables are the same. In rare cases the query will include 2 or more of these datasets, and I therefore can't tell them apart using QueryToClass, as they have the same FieldName.

EG I have two tables in my database, one for GHI Irradiance, and the other for POA Irradiance. Both have a column name "Irradiance." If the user wishes to graph both against each other:

private RO = DB.QueryToClass(SQLTools.MySQLHandle, SQLQuery) 

RO.FieldNames // contains: {"Time_Stamp", "Irradiance", "Irradiance"}

GraphTrace1 = evaluate(format("RO.%s", RO.Fieldnames[1]))
GraphTrace2 = evaluate(format("RO.%s", RO.Fieldnames[2]))		//Ambigious, always uses data from the first RO.Irradiance

Is there a way to access the data some other way than via the FieldNames string array?

Share this post

Link to post
Share on other sites

The best way to do this is to use the AS SQL keyword to provide an alias for the desired tag.  For example:

select myField as myAlias from myTable;

This is actually the only way to do SQL function selects, for example:

select sum(myField) as theSum from myTable;

or more common:

select min(myTimeFIeld) as startTime from myTable;

Of course your SQL commands may differ slightly due to the varying dialects of SQL.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now