How to concatenate my sql statement..?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
snop21
Posts: 90
Joined: Mon Jan 20, 2014 2:54 pm

How to concatenate my sql statement..?

Post by snop21 » Sat Mar 08, 2014 3:35 am

Hello livecoders,


Just wanna ask how can I concatenate my sql statement I have 100 columns in my table in my script

--------->    put "CREATE TABLE CBMS_Details (A_1A char(10), City A_1B(10), A_1C char(10), A_1D char(10) \
,A_1E char(10))" into tSQL
    --------> revExecuteSQL conn, tSQL

so I wanna make it 10 columns each line I tried the script above it was wrong. I use \ to concatenate.. Not working..

Need help..

Thank you..

Regards

-snop21

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: How to concatenate my sql statement..?

Post by Simon » Sat Mar 08, 2014 4:00 am

Code: Select all

    put "CREATE TABLE CBMS_Details (A_1A char(10), City A_1B(10), A_1C char(10), A_1D char(10)"& \
",A_1E char(10))" into tSQL
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: How to concatenate my sql statement..?

Post by SparkOut » Sat Mar 08, 2014 9:37 am

Or if it is just for legibility, then it can be much more readable to break up the string into sections...

put "CREATE TABLE CBMS_Details " into tSQL
put "(A_1A char (10))" after tSQL

Obviously add the rest of the column definitions - I did not as I am on phone keyboard and too lazy.

If you go even further you can make it something like

put "CREATE TABLE CMS_Details" into tSQLaction
put "(A_1A char (10))" into tSQLoptions
put tSQLaction && tSQLoptions into tSQL

Note the differences in handling space between clauses.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to concatenate my sql statement..?

Post by Klaus » Sat Mar 08, 2014 1:33 pm

You are trying to concatenate a STRING with \, but that does only work with a SCRIPT!
Simon and SparkOut already gave the solution.

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: How to concatenate my sql statement..?

Post by bangkok » Sat Mar 08, 2014 6:48 pm

With 100 columns... with you bother to type the query ?

You should use a loop to create it.

Code: Select all

put "CREATE TABLE CBMS_Details (" into tSQL

repeat with i = 1 to 100
put "A_"&i&"A char(10), City A_"&i&"B(10), A_"&i&"C char(10), A_"&i&"D char(10),A_"&i&"E char(10)," after tSQL
end repeat

delete last char of tSQL
put ")" after tSQL
revExecuteSQL conn, tSQL

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to concatenate my sql statement..?

Post by Klaus » Sat Mar 08, 2014 6:56 pm

YES! :D



Your message contains 7 characters. The minimum number of characters you need to enter is 10.

Post Reply