Can I execute more than one query in one script?

Copper 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.