How create a Query with both a Prompt and WITH

I am trying to create a Query. My design uses both WITH and a colon prompt. SQL Direct does not support prompts, and my reading is that the GUI does not support WITH. (Am I wrong on that?)

Is it possible to create a Query that uses both a colon prompt and the SQL clause WITH?

If I use WITH and turn off SQL Direct then the query will not save – I get “Syntax error in SQL statement.” The query is, however, apparently syntactically correct because if I turn on SQL Direct then the query will run without error.

Charles

You are detecting why we use filter tables to search stuff.
.
You can not mix :parameter and direct mode, but you can have a separate table (only one line) where you store the parameter. Then replace :parameter with
(SELECT parameter FROM paraTable WHERE id=1) or similiar.

@Wanderer I get what you are saying about filter tables.

How would that work interactively? I want to use this query in a report where when the user runs the report they would get a pop-up “Please_enter_route_letter”.

I do it just the other way round: I have a input box (“letter” in your case) and the button to the right calls teh filtered report, if the input box is not empty

@Wanderer clarifying, you would create a Form. The Form would have an input box labeled “Route Letter” and a button “Run Route Report.” When the user entered a route letter and clicked the button, you would write the route letter to row 1 of paraTable and then invoke the Report which would be based on a Query that would use paraTable as you describe above.

Is that correct? Or am I missing what you are trying to say?

Please pardon my lack of LO and database knowledge.
Charles

(post deleted by author)

All-purpose filter table with one row. Add more rows for more filter forms.

CREATE TABLE "FLT"("D1" DATE,"D2" DATE,"INT1" INTEGER,"INT2" INTEGER, "INT3" INTEGER, "DEC1" DECIMAL(7,2),"DEC2" DECIMAL(7,2), "TXT1" VARCHAR(50), "TXT2" VARCHAR(50), "TXT3" VARCHAR(50),"BOOL1" BOOLEAN, "BOOL2" BOOLEAN, "DESCR" VARCHAR(200),
"FID" SMALLINT NOT NULL PRIMARY KEY);
INSERT INTO "FLT" ("FID") VALUES (0);

Create a form with source type “SQL” and source SELECT * FROM "FLT" WHERE "FID"=0
Form properties:

  • Modify =Yes
  • Insert = No
  • Delete = No
  • Navigation bar = No

This setup ensures that you can’t tab into the next record or into the new record of that table.

Subform:
Some table or query with pairs of master/slave fields. This simple setup is limited to pairs like Master.A = Slave.X AND Master.B = Slave.Y, and when any of the master fields is empty, the subform remains blank.
Any slightly more advance pairing (Master >= Slave, Master LIKE %Slave%, function(Master)<Slave OR Master IS NULL) requires parameter queries in parsed mode with named parameters. Then map the master fields to the subform’s parameter names, without leading colon.

2 Buttons:

  • A cancel button (Action: Undo data entry) belonging to the filtering main form.
  • An OK button (Action: Refresh form) belonging to the filtered subform.

https://ask.libreoffice.org/uploads/short-url/6lJYIqihU01BD1nOGoeDVi5ofmB.odb
Uses a paramter query

SELECT "PID", "CID", "D", "V", "ID" 
FROM "Data" 
WHERE ( "PID" = :paramP OR :paramP IS NULL ) 
AND ( "CID" = :paramC OR :paramC IS NULL ) 
AND ( "D" >= :paramD1 OR :paramD1 IS NULL ) 
AND ( "D" <= :paramD2 OR :paramD2 IS NULL )
  • Missing arguments are ignored because :param=Something OR :param IS NULL returns True if either the criterion matches or if the criterion is missing.
  • The date is compared with 2 parameters using operators <= and >=.
  • We can easily filter by list box values comparing integers with integers.
  • The filtered record set is editable because we simply select all columns of a single table.

@Villeroy thanks much! I will keep this for reference.

I solved my problem using SELECT COUNT rather than WITH which means I could keep the Prompt. Keeping the prompt means less re-structuring of the whole thing (and re-training my user LOL).

Thanks again, everyone, for your patience with my newbie ignorance.

Charles