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?

Link to comment
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.


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.