MSSQL variable all problem

Hi i am highly newbie about grafana,

My question about variables. Does Grafana support drilldown variables? I mean when i choose or select option/field on one variable. And other variable can change automatically/properly depend of data of course. Like a master detail relationship. e.g continent, country

And another question is the correct way to usage of variable like hard coded where clause for MS Sql server ?

How do you deal with the all value of option in the variable. lets assume we have a variable and it has distinct values and all option. like continents in the world. But my query stuck when i choose the all option.

My query hard coded query looks like

select
time,
metric,
value
from table
where column1 IN (@variable1)

when i select the all option my query looks like

where column1 IN (’’)

what is the correct solution of this problem.

Many thanks.

@variable1 is a sql variable. To reference a Grafana variable use $variable1.

of course i am having a problem with value of variables. when i select the all option my query doesn’t work.
WHERE ColumnName IN ($variable) output of this -> WHERE ColumnName IN (’’)
this query getting empty resultset because of ‘’.

My Main questionis : Can Grafana handle T-sql query’s where clause. If i select all option grafana remove "ColumnName IN ($variable) "

IF i select one or more option in the variable everything works well.

Thanks

when i select the all option my query doesn’t work.

It should work. What Grafana version? Are you using a custom all value?

I did with this where clause I setted the value of custom all values ‘’. My main problem is t-sql oriented. if i select all option grafana sets empty as a value, otherwise when i select multiple value grafana gives me comma seperated values list such as ‘val1’,‘val2’ then i couldn’t use this these two kinds of different things.
case 1 => ‘val1’,‘val2’
case 2 =>
this is really blank nothing in it. :slight_smile:

You know SQL server uses ’ character for string then i have to handle both empty thing and comma seperated values at the same time. Finally i solved with the CONCAT function for this limitations.

CONCAT can concatenate many comma seperated values as a built in function in SQL Server .

WHERE
((LEN(CONCAT($Unvan,’’))=0) OR UNVAN IN ($Unvan))

I hope we had save someone’s day.

Thanks for your help btw @mefraimsson

You still haven’t told me what Grafana version you’re using. On latest master (commit 25ea5fc) using Postgres (but should be same for MySQL) I get the following result using All event types:

I using MSSQL
I having the same Problem my Data Source marked below by $Database is working fine when embed in SQL as shown below but when pass variable Query based it failed my version of Grafana is Grafana v5.2.4 (0bbac5c)

The SQL is
DECLARE
@StartDate datetime = __timeFrom(), @EndDate datetime = __timeTo()

SELECT Count(* ) as ‘Total Runs’, ‘$Database’ as ‘Project’,’$App’ as ‘Application’
FROM (RUN.RN_EXECUTION_DATE BETWEEN @StartDate and @EndDate )and
RUN.RN_STATUS Not in (‘No Run’, ‘N/A’, ‘Not Completed’, ‘’) and RUN.RN_DRAFT in (‘N’) and RUN.RN_USER_TEMPLATE_02 in (’$App’)