C# - applySQL. "Select sum()......"
Hello colleagues, I have a problem. I'm trying to do a SQL, select sum(.....). The code doesn't give me an error, but I don't know how to access the value of the variable later.
If you see my code, I have assigned a name to the value received, but when I execute the code, it always gives me "0", which is the value I have entered if there is nothing.
[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:cf66ea03-c953-4381-876e-bad88390f9e3:type=csharp&text=Innovator%20innovator%20%3D%20this.getInnovator%28%29%3B%0A%0A%2F%2F%20var%20innovator%20%3D%20new%20Innovator%28%29%3B%0A%0Astring%20ID%20%3D%20this.getID%28%29%3B%0A%0A%2F%2F%20esto%20sumaria%20todas%20las%20etapas%0Avar%20SentenciaSql%20%3D%20%22%20select%20sum%28MT_R_RUT_ETA.mt_rp_rut_eta_ltime%29%20as%20%27Resultado%27%22%2B%0A%22%20from%20innovator.MT_RUTA%20%22%2B%0A%22%20join%20innovator.MT_R_RUT_ETA%20on%20MT_RUTA.id%20%3D%20MT_R_RUT_ETA.SOURCE_ID%20%22%2B%0A%22%20where%20MT_RUTA.id%20%3D%20%27%22%2BID%2B%22%27%22%3B%0A%0Avar%20ResultadoSQL%20%3D%20innovator.applySQL%28SentenciaSql%29%3B%0A%0A%2F%2F%20tomamos%20el%20valor%20de%20la%20suma%0Avar%20LT_Tot%20%3D%20ResultadoSQL.getProperty%28%22Resultado%22%2C%220%22%29%3B%0A%0A%2F%2F%20esto%20sumaria%20todas%20las%20etapas%20MENOS%20APROVISIONAMIENTO%0ASentenciaSql%20%3D%20%22%20select%20sum%28MT_R_RUT_ETA.mt_rp_rut_eta_ltime%29%20as%20%27Resultado%27%22%2B%0A%22%20from%20innovator.MT_RUTA%20%22%2B%0A%22%20join%20innovator.MT_R_RUT_ETA%20on%20MT_RUTA.id%20%3D%20MT_R_RUT_ETA.SOURCE_ID%20%22%2B%0A%22%20where%20MT_RUTA.id%20%3D%20%27%22%2BID%2B%22%27%20and%20MT_R_RUT_ETA.KEYED_NAME%20not%20like%20%27APROV%25%27%22%3B%0A%0AResultadoSQL%20%3D%20innovator.applySQL%28SentenciaSql%29%3B%0A%0A%2F%2F%20tomamos%20el%20valor%20de%20la%20suma%0Avar%20LT_Par%20%3D%20ResultadoSQL.getProperty%28%22Resultado%22%2C%220%22%29%3B%0A%0A%2F%2FString%20s%20%3D%20LT_Tot.ToString%28%29%20%2B%20%22%20-%20%22%20%2B%20LT_Par.ToString%28%29%3B%0AString%20s%20%3D%20ResultadoSQL.ToString%28%29%3B%0Areturn%20innovator.newError%28s%29%3B]
I do it using SQL because it is faster than creating an AML and going through it to add the values.
1.- There is something similar in AML to "select sum"
2.- How can I pass the value of "SQLResult" to a variable to be able to display it on the screen.
In c# I usually use:
return innovator.newError(s);
With this the execution stops and it shows me "s".
Too many thanks!!!!!!
Hi,
glad to see you haven´t given up yet! :)
Normally SQL is executed form server Method. Does your version really work from a client Method?
One issue that I notice are these two lines:
ResultadoSQL = innovator.applySQL(SentenciaSql);
// tomamos el valor de la suma
var LT_Par = ResultadoSQL.getProperty("Resultado","0");You execute the SQL, but than immediately want to read a column of the result. But you haven´t got the result item itself yet. applySQL can return multiple items!
Try something like this
Item sqlItem = ResultadoSQL.getItemByIndex(0).getProperty("Resultado","0");
To my knowledge there is no inbuilt option to make "SUM". You can replicate "Count", but for other stuff you would need a custom Method, like described here: link
But for your use case (updating multiple very specific relationships), using SQL is ok.