SQL question

Kay C Lan lan.kc.macmail at gmail.com
Wed Sep 19 22:40:54 EDT 2012


During development a useful couple of lines of code are, assuming you've
been through your repeat for each col_name loop to create your query with
it's many OR conditions:

put tQuery into tTemp
replace comma with cr in tTemp
replace " OR " with cr & " OR " in tTemp
--replace " AND " with cr & " AND " in tTemp -- if appropriate
put tTemp into fld "tempDisplay" -- or MSG

What this does is takes your single very long line query:

SELECT 1Col,2Col,3Col,4Col,...,xCol FROM table WHERE (1Col LIKE '%or%' OR
2Col LIKE '&or%' OR 3Col LIKE '%or%' OR 4Col LIKE '%or%' OR ... LIKE '%or%'
OR xCol LIKE '%or%')

and makes it easier to debug the important bits:

SELECT 1Col
2Col
3Col
4Col
...
xCol FROM table WHERE (1Col LIKE '%or%'
 OR 2Col LIKE '&or%'
 OR 3Col LIKE '%or%'
 OR 4Col LIKE '%or%'
 OR ... LIKE '%or%'
 OR xCol LIKE '%or%')

All the column names should be all lined up so it makes tracking down
spelling or formatting errors so much easier.

HTH



More information about the use-livecode mailing list