[fpc-pascal] Create dynamic SQL according to available params
mike.cornflake at gmail.com
Thu Apr 7 14:25:34 CEST 2016
On 7 April 2016 at 20:00, Luiz Americo Pereira Camara <
luizamericop at gmail.com> wrote:
> Is there any code that given a SQL Template would generate the second
filter when paramy is available and keep blank when not available?
Nope, or at least I don't think so. I've spent a long time looking as
well. Been meaning to bring up the discussion either here or in the forum
I ended up implementing my own "Macro" functionality. Unfortunately I've
broken a few rules and tied the functionality to the UI, making it hard to
I need this all the time. My primary usage is in Master-Detail
relationships, where I always want the Master to contain an "ALL" option.
To achieve I write SQL's like...
Select Incident_Type As "Incident_Type",
Description As "Description",
'Where Incident_Type=''' || Incident_Type || '''' As "Filter_ID"
'(ALL)' As "Incident_Type",
'All Types' As "Description",
'' As "Filter_ID"
The first Select returns the Master Table, the second Select appends my
ALL. Note that "Filter_ID" contains my full SQL Where clause.
Over in my Detail SQL, I can write stuff like
Order By Incident_Type, Incident
I implement the detail refresh myself (easy), and I implement the Macro
substitution myself before executing the Detail SQL. (Any SQL field ending
in _ID is automatically hidden in my code)
I use this so often, and in so many different ways (Macro's don't have to
contain Where clauses, they can be any SQL elements, including simple
data), that I cannot consider SQL development without it. And as such,
I've often wondered how do others deal with this...
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal