# Use part of the variable in mysql query?

**URL:** <https://community.grafana.com/t/use-part-of-the-variable-in-mysql-query/37761>\
**Category:** General\
**Tags:** templating, mysql\
**Created:** [October 9, 2020, 9:58pm UTC](https://community.grafana.com/t/use-part-of-the-variable-in-mysql-query/37761 "2020-10-09T21:58:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![halisemre](https://avatars.discourse-cdn.com/v4/letter/h/a698b9/32.png) [@halisemre](https://community.grafana.com/u/halisemre)\
**Post date:** [October 9, 2020, 9:58pm UTC](https://community.grafana.com/t/use-part-of-the-variable-in-mysql-query/37761/1 "2020-10-09T21:58:26Z")

</div>

I have a variable named “name”.  
When I use $name in the mysql query (to construct graphs) i can obtain the string “AAAVVV”, but i hope i can get the string “AAA”,is there anyway to achieve the function ?

---

<div class="post-metadata">

**Author:** ![pooh](https://avatars.discourse-cdn.com/v4/letter/p/f05b48/32.png) [@pooh](https://community.grafana.com/u/pooh)\
**Post date:** [October 9, 2020, 10:24pm UTC](https://community.grafana.com/t/use-part-of-the-variable-in-mysql-query/37761/2 "2020-10-09T22:24:48Z")

</div>

Are you saying that you have a Grafana variable named “name” and whose value  
is “AAAVVV”, or that you have a Grafana variable named “name”, which, when you  
include it in a MySQL query, returns the MySQL value “AAAVVV”?

Also, you say that you can obtain the string “AAAVVV” but you hope to get the  
string “AAA”. What is the rule here? Are you looking for the left-most  
string of consecutively-identical characters, or the left-most three  
characters, or the string with “VVV” removed, or the string with the three  
right-most characters removed, or something else I haven’t thought of?

MySQL has several string manipulation functions, and would think at least one  
of these would be able to do what you want.

Maybe give us more than a single example - show us what you hope to get  
instead of what you already get, when what you already get is:

```
AAABBB
AAAAXX
ABCDEF
ABCDE
ABCDEFG
AABBCC
AAAAAA

```

and any other examples which you think would help to illustrate the inputs and  
outputs of the function or expression which you’re looking for.

Antony.

---

<div class="post-metadata">

**Author:** ![halisemre](https://avatars.discourse-cdn.com/v4/letter/h/a698b9/32.png) [@halisemre](https://community.grafana.com/u/halisemre)\
**Post date:** [October 12, 2020, 12:15am UTC](https://community.grafana.com/t/use-part-of-the-variable-in-mysql-query/37761/3 "2020-10-12T00:15:07Z")

</div>

I have a variable $name, the value format of the variable is AAAVVV, CCCDDD etc.

in mysql query I need to use part of $name (Example: AAA) but not the whole of it.

---

<div class="post-metadata">

**Author:** ![deejayluk](https://avatars.discourse-cdn.com/v4/letter/d/cc9497/32.png) [@deejayluk](https://community.grafana.com/u/deejayluk)\
**Post date:** [October 12, 2020, 4:56am UTC](https://community.grafana.com/t/use-part-of-the-variable-in-mysql-query/37761/4 "2020-10-12T04:56:55Z")

</div>

I think this topic is closed 🙂  
solution is below

> [@Trying to understand variables](https://community.grafana.com/t/trying-to-understand-variables/37688/20):
>
> I have found a solution. I used views in mysql.
