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’)

What is the generated sql output?

Hello. I have the same problem
How to use parameter from parameter, for example,
1parameter- $par1 = select top 100 Product from Products
2parameter- $par2 = select top 100 * from Customer as C Where c.Product=$par1
(in Microsoft Report builder its 2parameter- @par2 = select top 100 * from Customer as C Where c.Product=@par1 and it will work, how can i do the same in Grafana)

c.Product IN($par1) if $par1 is multi-value variable.

Hello All
i want to create a variable based on different-2 databases of same host
when i changed datasource db also change is it possible?

1 Like

Like this with Variable $DB having DB1, DB2, DBx etc

SELECT Col1, Col2, Col3, Colx… FROM $DB.[dbo].[TableName]

I tried this but didn’t get far

Better of to have Multiple queries with a where clause to NULL the outputs you don’t want

what do you have for your options?

image