Concatenate Data Base sentences

Hello

I have a follow questions about the string.

I try to use a MySql select sentence like as:

long carNum = 9947236;

char QUERY_POP = "SELECT expTarNumero, expTarEstado, expTarSaldo FROM expoTech.expTarjetas where expTarNumero = " + carNum;

char query[128];

When I compile thw code, the result is:

Ejercicio43-mySqlAlberto1:14: error: initializer fails to determine size of 'QUERY_POP'

char QUERY_POP = "SELECT expTarNumero, expTarEstado, expTarSaldo FROM expoTech.expTarjetas where expTarNumero = " + tarjeta;

My question, how I do to concatenate the SELECT sentence with the card number.

I new programming in arduino.

Thank you for the help.

My question, how I do to concatenate the SELECT sentence with the card number.

char query_pop[128];
sprintf(query_pop, "SELECT expTarNumero, expTarEstado, expTarSaldo FROM expoTech.expTarjetas where expTarNumero = %ld", carNum);

Note that upper case names are, by convention, reserved for constants, and query_pop is NOT a constant.

Note, too, that the format specifier is ld, for long integer.

Hello Paul

I try to use you answer, but not work.

I include the code.
In the line 13, define a variable with the card number.
char tarNum = “9947236”;

In the line 14, define a SELECT sentence
char query[] = “SELECT expTarEstado FROM expoTech.expTarjetas where expTarNumero = %ld”, tarNum;

The error description is: Redefinition of 'char tarNum.

But, i dont know how solved :frowning:

Appreciate you help.

Thank you

Ejercicio43-mySqlAlberto1.ino (1.7 KB)

compileErrors.txt (10.2 KB)

Sorry, I include a wrong code.

This is the correct code.

Thank you

Ejercicio43-mySqlAlberto1.ino (1.85 KB)

Ejercicio43-mySqlAlberto1.ino (1.85 KB)

char tarNum = "9947236";

I KNOW that the compiler didn't let you do that.

char tarNum = '9947236';

Please post a picture of your keyboard, with that ONE key circled.

char query[] = "SELECT expTarEstado FROM expoTech.expTarjetas where expTarNumero = %ld", tarNum;

Complete nonsense.

I showed you how to do what you want to do in reply #1. I can't help that you can't read and follow directions.

Hello Paul.

Thanks a lot. It work with the instructions of the reply #1.
I read about the speintf and I understand the function.

Best regads