-
Notifications
You must be signed in to change notification settings - Fork 0
pts script syntax loopsql
full_sql_select_statement should be a complete SQL SELECT statement to gather the records that you require; it will be passed almost verbatim to the database drivers. Like the data for the TEXT command it can contain embedded variables, which will be translated before passing through.
Unlike standard WHERE clauses it cannot contain CURRENT."field_name". If you need this then you should use VARIABLE_FIELD to assign the field to a variable, and embed the variable instead.
Since SQL requires single quotes around strings, if you are embedding variables in the string, they must still be surrounded in the single quotes – this is not done automatically. This allows a numeric variable to be entered and still form legal SQL.
Since a SELECT statement can contain table joins, this can be used to simplify and speed up scripts by combining what would originally have been nested loops into a single action. However, unlike in most implementations of SQL, if two tables have a field of the same name, these cannot be accessed separately within your script. This is because fields are only accessed by the field name, with no table to qualify it. To overcome this you should us SQL’s AS keyword to create an alias for the field name. This will then provide a unique name that can be used to extract the field.
NODATERANGE and SORTBY / REVERSE_SORTBY are not supported when using raw SQL syntax. Doing so will confuse the parser and will most likely result in failure. ROW_COUNT is still supported as normal.
Examples:
(Statement split over multiple physical lines for clarity only)
LOOP SQL “SELECT * FROM [Away Talks]
WHERE [Brother]
LIKE ‘$strThisBrother’
ORDER BY [Talk Date];” ROW_COUNT $iNumRows
...
END_LOOP
LOOP SQL "SELECT [Congregation Speakers].Speaker,
[Congregation Speakers].Notes,
Congregations.Notes AS [CongNotes]
FROM [Congregation Speakers]
INNER JOIN Congregations
ON [Congregation Speakers].Congregation = Congregations.Congregations"
ORDER BY [Congregation Speakers].Speaker"
ROW_COUNT $iNumRows
FIELD "Notes" (the speaker notes)
EOL
FIELD "CongNotes" (was the congregation Notes field, now aliased)
EOL
END_LOOP
Copyright © 2002 - 2025 by Andrew Truckle. All Rights Reserved.
- Using Public Talks
- Main Application Menu
-
Database Ribbon Panel
- Assignments Editor
- Backup Database
- Check Talk Exchange
- Compact Database
- Convert Database
- Create Unassigned Date Entries
- Database Security
- Maintain Databases
- Purge Database
- Rearrange Dates
- Restore Database
- Help Ribbon Panel
-
Home Ribbon Panel
- Create a Report
-
Manage Custom Reports
- Editing Scripts
- Content Ribbon Panel
- System Ribbon Panel
- Script Command Syntax
-
Tutorials
- Using The Script Editor
-
How To Write Scripts
- Module 1 - The Basics
- Module 2 - Hello, World!
- Module 3 - Multiple Text Blocks
- Module 4 - It's A Date, Then
- Module 5 - Oh, I'm Blushing!
- Module 6 - It is a Rainbow!
- Module 7 - The Font Of All Knowledge
- Module 8 - Queue To The Right
- Module 9 - Memory Like An Elephant
- Module 10 - May I Squeeze In There?
- Module 11 - Move Over, Please
- Module 12 - You Move Over Here
- Module 13 - Is My Back A Funny Colour?
- Module 14 - I'm Going Loopy Here!
- Module 15 - Fields Of Golden... Text
- Module 16 - Man, That Looks Weird
- Module 17 - Inner Peace, Inner Loop
- Advanced Script Features
- Quick Access Toolbar
- Settings Ribbon Panel
- Tools Ribbon Panel
- Revision History
- Contact Information