Page 1 of 1

How to format a string as a parameter for IN clause

Posted: Thu 17 Feb 2005 18:04
by kk
I just converted an app from BDE to SDAC but the query does not returns data anymore. I found out that the problem is with the string that i pass in the IN clause. The query is like this.

SELECT *
FROM tblABC
WHERE Item IN(:Item)

:Item = 'Item1','Item2'
This fails.

The query works if i set parameter to only one Value

:Item = 'Item1'
This works.

How should i format the string?
It used to work in BDE though.

Posted: Mon 21 Feb 2005 15:57
by Ikar
Looks like MS SQL Server restriction. Try to use macros instead of parameters:

Code: Select all

   MSQuery.SQL.Text := 'SELECT au_lname, state FROM pubs..authors WHERE state IN (&p)';
   MSQuery.Macros[0].Value := '''CA'', ''IN'', ''MD''';
   MSQuery.Execute;
PS: curiously, that BDE processes these queries at you.
If you send us BDE-example we'll try to reproduce this behaviour.

Posted: Sun 27 Feb 2005 20:31
by Guest
Thanks for your reply.
Your components are excellent. Well done and keep it up ;)
Ikar wrote:PS: curiously, that BDE processes these queries at you.
If you send us BDE-example we'll try to reproduce this behaviour.
Im sorry im mistaken, BDE has the same problem. I was generating the SQL command in code and passing to the Query component so the query worked in BDE.