Use part of the variable in mysql query?

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 ?

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.

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.

I think this topic is closed :slight_smile:
solution is below