Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to pass parameters to Query with IN Clause


This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Feb 3, 2016 7:07 AM Last Post By: Serge Girard
Marko Ravnik

Posts: 23
Registered: 12/8/13
How to pass parameters to Query with IN Clause  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 3, 2016 6:42 AM
Hello!

I have a query:
SELECT * FROM `table` WHERE `Field1` IN :IDMERRANGE

and values i would like to pass are 1,2,3 as integers so the query shuld look like: SELECT * FROM `table` WHERE `Field1` IN (1,2,3)

How can I pass parameters IDMERRANGE to query with method "FDQuery.ParamByName('IDMERRANGE')"?

I work with Delphi XE5, MySQL and FireDac.
Jeff Overcash (...

Posts: 1,529
Registered: 9/23/99
Re: How to pass parameters to Query with IN Clause
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 3, 2016 6:50 AM   in response to: Marko Ravnik in response to: Marko Ravnik
Marko Ravnik wrote:
Hello!

I have a query:
SELECT * FROM `table` WHERE `Field1` IN :IDMERRANGE

and values i would like to pass are 1,2,3 as integers so the query shuld look like: SELECT * FROM `table` WHERE `Field1` IN (1,2,3)

How can I pass parameters IDMERRANGE to query with method "FDQuery.ParamByName('IDMERRANGE')"?

I work with Delphi XE5, MySQL and FireDac.

you can't. That isn't how parameters work. They are not macro expansions.
FireDAC does have the ability to do macro expansions though, but not through
parameters (TParams).

--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
Learning is finding out what you already know. Doing is demonstrating that you
know it. Teaching is reminding others that they know it as well as you. We are
all leaners, doers, teachers. (R Bach)

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
Serge Girard

Posts: 29
Registered: 1/5/02
Re: How to pass parameters to Query with IN Clause  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 3, 2016 7:07 AM   in response to: Marko Ravnik in response to: Marko Ravnik
Hi,

use macro instead and perhaps in a little different way

SELECT * FROM `table` !mysel
and
Query.macrobyname('mysel').asraw:='WHERE Field in (1,2,3)';

or

SELECT * FROM table WHERE !mysel

no selection Query.MacroByName('mysel').asRaw:'1=1';
a selection Query.MacroByName('mysel').asRaw:'Field in (1,2,3)';
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02