Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Need Help with SQL Query [TQuery]

Posted on 2007-10-11
5
Medium Priority
?
214 Views
Last Modified: 2010-08-05
Hi again,

I need some help with SQL here.

I am populating a listbox with codes.

e.g: AD3454
       AD5446
       AD6657
etc...

I need an SQL Query like this:

SELECT * FROM products where AccountID = [SomeVariable] BUT is not is not Listbox List.

So it will not show the records with the codes which are in the Listbox.

Thanks

ST3VO
0
Comment
Question by:ST3VO
  • 2
  • 2
5 Comments
 
LVL 19

Expert Comment

by:MerijnB
ID: 20055508
so if I understand correctly you want a query to retrieve all records which are _not_ listed in the listbox?
0
 

Author Comment

by:ST3VO
ID: 20055516
Yes Please!  :o)
0
 
LVL 19

Accepted Solution

by:
MerijnB earned 2000 total points
ID: 20055534
try this:

procedure TForm14.Button1Click(Sender: TObject);
var Exclude: TStringList;
    i: integer;
    Query: string;
begin
 Exclude := TStringList.Create();

 try
  for i := 0 to ListBox1.Count - 1 do
   Exclude.Add(QuotedStr(ListBox1.Items[i]));

  Query := Format('SELECT * FROM products where not (AccountID in (%s))', [Exclude.CommaText]);
 finally
  Exclude.Free();
 end;
end;
0
 

Author Comment

by:ST3VO
ID: 20055720
Works great!  I mean my question was answered although I've got further problems but I am opening a new question for this because you answer perfectly work and answered my question!

Please check my new question if you can!

Thanks

ST3VO


0
 
LVL 6

Expert Comment

by:bokist
ID: 20056100
one of possible solutions :

  Query.sql.add('SELECT * FROM products where not AccountID in :p1');
  Query.parameters.parambyname('p1').asstring := '[' + Exclude.Text + ']';
  Query.Open;
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Loops Section Overview
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question