Real Software Forums
http://forums.realsoftware.com/

How to initiate SQL table column from variable
http://forums.realsoftware.com/viewtopic.php?f=3&t=47674
Page 1 of 1

Author:  Dralion [ Mon Apr 22, 2013 9:01 pm ]
Post subject:  How to initiate SQL table column from variable

I everyone
im trying to create Sql table with column came from a variable
So im try this line but i doesnt work... even if i dont have a error message from DB
my variable call b and it contains concanate version of my listbox column with comma
and it appear like this in a messagebox " Name,Phone,Email "
App.OrdersDB.SQLExecute "Create Table test ((Str(b)) Varchar)"

in fact i need help to insert variable in sql in CREATE table...INSERT data and SELECT statement
thanks

Author:  timhare [ Mon Apr 22, 2013 9:25 pm ]
Post subject:  Re: How to initiate SQL table column from variable

First, build the string in a variable and examine it in the debugger. Use string concatenation, eg.,

dim sql as string
sql = "Create table test ((" + b + ") Varchar)"
break // to examine the results
App.OrdersDB.SQLExecute(sql)

Author:  Dralion [ Tue Apr 23, 2013 3:08 am ]
Post subject:  Re: How to initiate SQL table column from variable

thank you timhare
iv just remove a set of paranthese and it work
sql = "Create table test (" + b + " Varchar)"

result
Create table test (Name,Phone,Email Varchar)
But it apply varchar only on the last column...is there a way to apply Varchar to all added column.
Do i have to insert it in my concatenate function?
And i try to apply same logic to insert... where can i find example
because
sql = "Insert into test ("+ b + Values ('Winnie','Sales','3500')")
Doesnt work either :(

Author:  timhare [ Tue Apr 23, 2013 3:29 am ]
Post subject:  Re: How to initiate SQL table column from variable

Dralion wrote:
thank you timhare
iv just remove a set of paranthese and it work
sql = "Create table test (" + b + " Varchar)"

result
Create table test (Name,Phone,Email Varchar)
But it apply varchar only on the last column...is there a way to apply Varchar to all added column.
Do i have to insert it in my concatenate function?

Most likely.

Quote:
And i try to apply same logic to insert... where can i find example
because
sql = "Insert into test ("+ b + Values ('Winnie','Sales','3500')")
Doesnt work either :(

You're missing a quote mark. Check the string in the debugger and adjust until you get what you want. Writing one language (sql) inside another language (RB) is always a challenge. But the debugger is your friend.

Author:  Dralion [ Tue Apr 23, 2013 9:00 am ]
Post subject:  Re: How to initiate SQL table column from variable

Thanks Timhare
Quote:
the debugger is your friend.
Now i know what it mean and yes i gonna use it much more

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/