Variables and Table Names

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Not a lot of thought
Posts: 77
Joined: Thu May 21, 2015 2:41 am

Variables and Table Names

Post by Not a lot of thought » Sun Oct 18, 2015 8:33 pm

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...

Not a lot of thought
Posts: 77
Joined: Thu May 21, 2015 2:41 am

Re: Variables and Table Names

Post by Not a lot of thought » Sun Oct 18, 2015 8:46 pm

...of course as soon as I post this I figure out the problem. Please disregard.

Klaus
Posts: 13823
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Variables and Table Names

Post by Klaus » Sun Oct 18, 2015 8:48 pm

Glad we could help! :D

golive
Posts: 98
Joined: Wed Jul 01, 2015 5:16 am

Re: Variables and Table Names

Post by golive » Tue Nov 03, 2015 7:43 am

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?

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Variables and Table Names

Post by MaxV » Wed Nov 04, 2015 6:06 pm

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
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

golive
Posts: 98
Joined: Wed Jul 01, 2015 5:16 am

Re: Variables and Table Names

Post by golive » Fri Nov 06, 2015 7:42 am

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.

Post Reply

Return to “Databases”