# Question about variable for MS SqlServer

**URL:** <https://community.grafana.com/t/question-about-variable-for-ms-sqlserver/9019>\
**Category:** Grafana\
**Created:** [July 21, 2018, 6:34am UTC](https://community.grafana.com/t/question-about-variable-for-ms-sqlserver/9019 "2018-07-21T06:34:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gisfinder](https://avatars.discourse-cdn.com/v4/letter/g/ba9def/32.png) [@gisfinder](https://community.grafana.com/u/gisfinder)\
**Post date:** [July 21, 2018, 6:34am UTC](https://community.grafana.com/t/question-about-variable-for-ms-sqlserver/9019/1 "2018-07-21T06:34:02Z")

</div>

Query type variable contains two fields, they are “name” and “code” of the metric.  
The query statement for variable is : select mID as \_\_Value , mName as \_\_Text from meterInfo  
While in dashboard drop down list the two fields are all visible, how to set only name field in the list?

![image](https://us1.discourse-cdn.com/grafana/original/2X/e/ef821a9dd5900357151ef2020ce341fd41c9bb97.png)

Another question is how to use this variable in dashboard to filter the metric? I tried it but failed.  
In the metric it is :  
SELECT  
$\_\_time(DT) ,  
TT11 as value,  
PACKAGENUM as metric  
FROM HEU.DBO.GIS24HOUR where PACKAGENUM = $huName

The sql result of generator result is:  
SELECT DT as time, TT11 as value, PACKAGENUM as metric  
FROM GIS24HOUR where PACKAGENUM = SSH0000001

I expect it should be:  
SELECT DT as time, TT11 as value, PACKAGENUM as metric  
FROM GIS24HOUR where PACKAGENUM = ‘SSH0000001’

 ![2018-07-21_14-36-36](https://us1.discourse-cdn.com/grafana/original/2X/9/9bf416880d94b53d9d80d5c0ac0042095ce86cbb.png)

---

<div class="post-metadata">

**Author:** ![gisfinder](https://avatars.discourse-cdn.com/v4/letter/g/ba9def/32.png) [@gisfinder](https://community.grafana.com/u/gisfinder)\
**Post date:** [July 24, 2018, 7:22am UTC](https://community.grafana.com/t/question-about-variable-for-ms-sqlserver/9019/2 "2018-07-24T07:22:18Z")

</div>

After research it deeper I found the solution.  
Firstly in the variable creation part , I mistake the \_\_Text, \_\_Value to \_Text, \_Value(one underscore is missed).  
The second is for the variables used in metric clause:  
It should be: where PACKAGENUM = ‘[[huName]]’  
then in the generated sql is : where PACKAGENUM = ‘SSH0000001’
