SQLSERVER- only the first sproc is executing in grafana

I have a variables/drop down of servers and serverports. I want to call a sproc per each combination of servers and serverports. This works in SQL server but not in Grafana. It only calls the first sproc.

DECLARE
  @StartDate datetime,
  @EndDate datetime,
  @i int, @j int, @ServerId smallint, @ServerName VARCHAR(100), @ServerPort VARCHAR(100)
SET
  @StartDate =  DATEADD(HH,-1,  GETDATE()) 
SET
  @EndDate = GETDATE()
SET
  @ServerName ='[[ServerName:csv]]'

SET
  @ServerPort =		'[[ServerPort]]'

select @i = 1 
while @i < len(REPLACE(@ServerName,',','')) + 1
begin
    set @j = 1 
    while @j < len(REPLACE(@ServerPort,',','')) + 1
    begin
       
		declare @ServerIDFromQuery smallint = ( select ServerID from Server where ServerName = (select * from dbo.fnSplit(@ServerName, ',' ,@i)) and ServerPort = CAST((select * from fnSplit(@ServerPort , ',' ,@j)) as int))
      execute  DiagnosticLogGetGrafana  @StartDate ,  @EndDate, @ServerIDFromQuery, 18
		set @j = @j + 1
    end
    set @i = @i + 1
end

How would I go about calling a sproc per each combination of servers+ports selected?

Bump.

I can’t figure out a way I can call a SQL stored procedure per variables/drop down selected.

You cannot use a while loop. Please repeat variable per panel and call sproc in each panel.

but what if I want it all in one panel? I did it InfluxDB where I had variables as different tags and I did GROUP BY different TAGSin the Netrics query section. Trying to do the same in mssql

I did base my answer on that you had a sproc only taking a parameter holding a server id. You can A) change your sproc to support a list of values or B) skip the sproc and write the query directly in query editor field using WHERE … column IN($variable).