Can I execute more than one query in one script?

%3CLINGO-SUB%20id%3D%22lingo-sub-110063%22%20slang%3D%22en-US%22%3ECan%20I%20execute%20more%20than%20one%20query%20in%20one%20script%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-110063%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20trying%20and%20I%20do%20not%20find%20how%20to%20execute%20more%20than%20one%20query%20in%20one%20script.%20I%20want%20to%20do%20this%20in%20order%20to%20parametrize%20some%20analysis.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20I%20execute%20more%20than%20one%20query%20in%20one%20script%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%2C%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-110063%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EApplication%20Insights%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20Log%20Analytics%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EQuery%20Language%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-110425%22%20slang%3D%22en-US%22%3ERe%3A%20RE%3A%20Can%20I%20execute%20more%20than%20one%20query%20in%20one%20script%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-110425%22%20slang%3D%22en-US%22%3E%3CP%3E%2F%2FMy%20example%2C%20requests%20that%20I%20want%20to%20analyze%3CBR%20%2F%3Elet%20tabla%20%3D%3CBR%20%2F%3Erequests%3CBR%20%2F%3E%7C%20where%20getmonth(timestamp)%20%3D%3D%20getmonth(FechaInicio)%20and%20getyear(timestamp)%20%3D%3D%20getyear(FechaInicio)%3CBR%20%2F%3E%7C%20where%20name%20%3D%3D%20APIIgual%20or%20isempty(APIIgual)%3CBR%20%2F%3E%7C%20extend%20dummy%20%3D%201%3CBR%20%2F%3E%7C%20join%20kind%3Dfullouter%20(%3CBR%20%2F%3EAPIContiene%20%7C%20extend%20dummy%20%3D%201%3CBR%20%2F%3E)%20on%20%24left.dummy%20%3D%3D%20%24right.dummy%3CBR%20%2F%3E%7C%20where%20name%20contains(llamada)%20or%20APIContieneDatos%20%3D%3D%20false%20%2F%2F%20como%20el%20unique%20innerjoin%20pero%20conn%20un%20or%3CBR%20%2F%3E%7C%20summarize%20by%20id%2Cname%2Cduration%2CresultCode%2Ctimestamp%3CBR%20%2F%3E%7C%20join%20kind%3Dleftanti%3CBR%20%2F%3E(%3CBR%20%2F%3EAPINoIgual%3CBR%20%2F%3E)%20on%20%24left.name%20%3D%3D%20%24right.llamada%3CBR%20%2F%3E%7C%20join%20kind%20%3D%20leftanti%20(%3CBR%20%2F%3Erequests%20%7C%20extend%20dummy%20%3D%201%3CBR%20%2F%3E%7C%20where%20getmonth(timestamp)%20%3D%3D%20getmonth(FechaInicio)%20and%20getyear(timestamp)%20%3D%3D%20getyear(FechaInicio)%3CBR%20%2F%3E%7C%20join%20kind%3D%20leftouter%20(%3CBR%20%2F%3EAPINoContiene%20%7C%20extend%20dummy%20%3D%201%3CBR%20%2F%3E)%20on%20%24left.dummy%20%3D%3D%20%24right.dummy%3CBR%20%2F%3E%7C%20where%20name%20contains(llamada)%20and%20APINoContieneTieneDatos%20%3D%3D%20true%3CBR%20%2F%3E%7C%20summarize%20by%20id%3CBR%20%2F%3E%7C%20project%20id%3CBR%20%2F%3E)%20on%20%24left.id%20%3D%3D%20%24right.id%3CBR%20%2F%3E%7C%20summarize%20by%20id%2Cname%2Cduration%2CresultCode%2Ctimestamp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%2F%2FTotal%2C%20Corrects%2C%20a%20Incorrects%20requests%20group%20by%20day%20and%20rendered%20as%20timechart%3C%2FP%3E%3CP%3Elet%20Peticiones%20%3D%20tabla%3CBR%20%2F%3E%7C%20summarize%3CBR%20%2F%3E%5B'Total'%5D%20%3D%20count()%2C%3CBR%20%2F%3E%5B'Correctas'%5D%20%3D%20count(resultCode!%3D500)%2C%3CBR%20%2F%3E%5B'Erroneas'%5D%20%3D%20count(resultCode%20%3D%3D%20500)%3CBR%20%2F%3Eby%20%5B'Dia'%5D%20%3D%20dayofmonth(timestamp)%3CBR%20%2F%3E%7C%20order%20by%20Dia%20asc%3CBR%20%2F%3E%7C%20render%20timechart%20by%20Dia%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%2F%2FAverage%20time%20response%20and%20max%20time%20response%26nbsp%3Bgroup%20by%20day%20and%20rendered%20as%20timechart%3C%2FSPAN%3E%3C%2FP%3E%3CP%3Elet%20Tiempos%20%3D%20tabla%3CBR%20%2F%3E%7C%20summarize%3CBR%20%2F%3E%5B'TiempoMedio'%5D%20%3D%20round(avg(duration)%2C0)%2C%3CBR%20%2F%3E%5B'TiempoMaximo'%5D%20%3D%20round(max(duration)%2C0)%3CBR%20%2F%3Eby%20%5B'Dia'%5D%20%3D%20dayofmonth(timestamp)%3CBR%20%2F%3E%7C%20order%20by%20Dia%20asc%3CBR%20%2F%3E%7C%20render%20timechart%20by%20Dia%3B%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%2F%2F%22Select%20Tiempos%22%3CBR%20%2F%3ETiempos%3B%3C%2FP%3E%3CP%3E%2F%2F%22Select%20Peticiones%22%3CBR%20%2F%3EPeticiones%3B%3CBR%20%2F%3E%3CBR%20%2F%3EThe%20main%20problem%20is%20that%20I%20only%20can%20have%20one%20result.%20%22Tiempos%22%20or%20%22Peticiones%22%20but%20no%20both.%20I%20need%20to%20use%20render%20timecharts.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20would%20be%20great%20having%20results%20tabs.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-110354%22%20slang%3D%22en-US%22%3ERE%3A%20Can%20I%20execute%20more%20than%20one%20query%20in%20one%20script%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-110354%22%20slang%3D%22en-US%22%3EAPI%20%2F%20Powershell%20cmdlets%20information%20at%20%3CA%20href%3D%22http%3A%2F%2Fdev.loganalytics.io%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fdev.loganalytics.io%2F%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-110352%22%20slang%3D%22en-US%22%3ERE%3A%20Can%20I%20execute%20more%20than%20one%20query%20in%20one%20script%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-110352%22%20slang%3D%22en-US%22%3EFor%20that%20I%20would%20use%20API%20or%20PowerShell%20Cmdlets.%20You%20can%20also%20use%20saved%20Functions.%20Can%20you%20elaborate%20with%20an%20example%20%3F%3C%2FLINGO-BODY%3E
New Contributor

Hi,

 

I am trying and I do not find how to execute more than one query in one script. I want to do this in order to parametrize some analysis.

 

Can I execute more than one query in one script?

 

Thank you,

3 Replies
For that I would use API or PowerShell Cmdlets. You can also use saved Functions. Can you elaborate with an example ?
API / Powershell cmdlets information at http://dev.loganalytics.io/

//My example, requests that I want to analyze
let tabla =
requests
| where getmonth(timestamp) == getmonth(FechaInicio) and getyear(timestamp) == getyear(FechaInicio)
| where name == APIIgual or isempty(APIIgual)
| extend dummy = 1
| join kind=fullouter (
APIContiene | extend dummy = 1
) on $left.dummy == $right.dummy
| where name contains(llamada) or APIContieneDatos == false // como el unique innerjoin pero conn un or
| summarize by id,name,duration,resultCode,timestamp
| join kind=leftanti
(
APINoIgual
) on $left.name == $right.llamada
| join kind = leftanti (
requests | extend dummy = 1
| where getmonth(timestamp) == getmonth(FechaInicio) and getyear(timestamp) == getyear(FechaInicio)
| join kind= leftouter (
APINoContiene | extend dummy = 1
) on $left.dummy == $right.dummy
| where name contains(llamada) and APINoContieneTieneDatos == true
| summarize by id
| project id
) on $left.id == $right.id
| summarize by id,name,duration,resultCode,timestamp;

 

//Total, Corrects, a Incorrects requests group by day and rendered as timechart

let Peticiones = tabla
| summarize
['Total'] = count(),
['Correctas'] = count(resultCode!=500),
['Erroneas'] = count(resultCode == 500)
by ['Dia'] = dayofmonth(timestamp)
| order by Dia asc
| render timechart by Dia;

 

//Average time response and max time response group by day and rendered as timechart

let Tiempos = tabla
| summarize
['TiempoMedio'] = round(avg(duration),0),
['TiempoMaximo'] = round(max(duration),0)
by ['Dia'] = dayofmonth(timestamp)
| order by Dia asc
| render timechart by Dia;


//"Select Tiempos"
Tiempos;

//"Select Peticiones"
Peticiones;

The main problem is that I only can have one result. "Tiempos" or "Peticiones" but no both. I need to use render timecharts.

 

It would be great having results tabs.