Page 1 of 1

Variables and Table Names

Posted: Sun Oct 18, 2015 8:33 pm
by Not a lot of thought
I'm having fits trying to create a table using a variable for its name. I have several truncated layers of storage in my app and need the program to generate unique names for each table, but I'm struggling to get it to work. I can get them to run if I define the table names, but if I set the same names in variables and use the variable to call the unique name for the new table in the database it doesn't execute the SQL.

"CREATE TABLE IF NOT EXISTS "&variableTbName&" (column1, column2,..etc);" into tSQL

I've keyed the exact same thing with the actual name I want to use and it works fine. I can't seem to figure out why it isn't working with the variable...help...

Re: Variables and Table Names

Posted: Sun Oct 18, 2015 8:46 pm
by Not a lot of thought
...of course as soon as I post this I figure out the problem. Please disregard.

Re: Variables and Table Names

Posted: Sun Oct 18, 2015 8:48 pm
by Klaus
Glad we could help! :D

Re: Variables and Table Names

Posted: Tue Nov 03, 2015 7:43 am
by golive
Not a lot of thought wrote:...of course as soon as I post this I figure out the problem. Please disregard.
And your solution is?

Re: Variables and Table Names

Posted: Wed Nov 04, 2015 6:06 pm
by MaxV
Try this:

Code: Select all

"CREATE TABLE IF NOT EXISTS '" & variableTbName & "' (column1 TEXT, column2 NUMBER,..etc);"  into tSQL
Note that I added the ' char before and after the " char

Re: Variables and Table Names

Posted: Fri Nov 06, 2015 7:42 am
by golive
MaxV wrote:Try this:

Code: Select all

"CREATE TABLE IF NOT EXISTS '" & variableTbName & "' (column1 TEXT, column2 NUMBER,..etc);"  into tSQL
Note that I added the ' char before and after the " char
OIC, thanks.