bms Posted June 7, 2022 Share Posted June 7, 2022 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? Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted June 8, 2022 Share Posted June 8, 2022 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.