cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

How to read/get SQL Query Output which is NUMBER

MA8731174
14-Alexandrite

How to read/get SQL Query Output which is NUMBER

This is my Query which returns the result in Infotable.

 

 

SELECT COUNT(*) AS TotalCount
FROM dbo.ML1QualityDataTable
WHERE lineName = [[lineName]]
AND CAST(qualityCheckTimestamp AS DATE) = CAST(GETDATE() AS DATE);

 

 

Result of Query:

 

Jamal8548_0-1711000136601.png

 

 

Now here is my service which executes the above service and get the result but here i am unable to get the result as an output. How to read this output of query from the JS service.   Mydatashape contains only one field named TotalCount of infotable type.

 

 

let mergedInfotable  = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
                        infoTableName: "InfoTable",
                        dataShapeName: "V2.TotalCount.DS"
                    });

let ab = Things['V2.MYSQLDatabaseController'].SQLQuery_GetTodaysEntriesCount({
   lineName:'ML1'
});

let a= mergedInfotable.AddRow(ab.rows[0]);
let result=a;
logger.info(ab.rows[0]);

 

 

 

i get this error:-

 

 Error executing service ComputeKey. Message :: Unable To Convert To Value Collection: Conversion Error on Field TotalCount : Unable To Convert From java.lang.Integer to INFOTABLE - See Script Error Log for more details.

ACCEPTED SOLUTION

Accepted Solutions
MA8731174
14-Alexandrite
(To:MA8731174)

I got the solution so it does not matter that if query returns the result as an infotable. We can access it as a number. Here is the code:

 

let ab = Things['V2.MYSQLDatabaseController'].SQLQuery_GetTodaysEntriesCount({
   lineName:'ML1'
});

let result= ab.TotalCount;

// I have set the output for this service as a number but the SQLQuery service output is infotable. 
//Happy Coding

View solution in original post

4 REPLIES 4
MA8731174
14-Alexandrite
(To:MA8731174)

I got the solution so it does not matter that if query returns the result as an infotable. We can access it as a number. Here is the code:

 

let ab = Things['V2.MYSQLDatabaseController'].SQLQuery_GetTodaysEntriesCount({
   lineName:'ML1'
});

let result= ab.TotalCount;

// I have set the output for this service as a number but the SQLQuery service output is infotable. 
//Happy Coding

Just so you know, this is just a shortcut/syntactic sugar version of

let result=ab.rows[0].TotalCount;

 

MA8731174
14-Alexandrite
(To:Rocko)

Thank you @Rocko for your reply, as my SQL query returns output as an infotable and only in one row which is TotalCount so just for testing i thought i can directly access it from infotable and access it but then i have discovered that it is just a NUMBER and i can access it direclty as above. 

Sure. I just wanted to make clear this is a special characteristic of the infotable how it provides quick access to the first row.

Announcements


Top Tags