How to use a variable as a table name in a MapInfo Pro query

Products affected: MapInfo Pro™
Users would need to build a query syntax and save it in a string variable of its own, for example:
Dim tabName as String
Dim cmd as String

tabName = "testTable"
cmd = "SELECT * FROM " + tabName
Run Command cmd

From the above code the table name is stored in tabName and the actual query is stored as a string in cmd. If users need to include the tabName variable they have to close off the string and use the + character to tie it together. This would also work if users wanted to include the Where clause, for example:

cmd = "SELECT * FROM " + tabName + " WHERE rowid = 3"

Please note that not all commands will work within the MapBasic window as they would in a compiled MapBasic script due to the compiler not being present which is why users cannot just run Print tabName.IntField from the MapBasic Window. However, users should find that the above commands all work fine in the MapBasic Window.
UPDATED:  October 9, 2017