0

how do I get a MySQL SELECT statement that takes a variable as table name.

As an example:

a = "table1"
b = "table2"

and so on...

Now I want to integrate these variables into the SELECT statement:

dbSendQuery(mydb, "select * from a")

I tried it with different comma variations but unfortunately without success. I also tried the percentage sign.

Can anyone tell me how I can solve this?

Thanks!

zx8754
  • 52,746
  • 12
  • 114
  • 209
Timothy_Goodman
  • 393
  • 1
  • 5
  • 18

1 Answers1

0
dbSendQuery(mydb, sprintf("select * from %s",a))

sprintf should help in this case. For more info on how this works try ?sprintf

Maylo
  • 572
  • 5
  • 16