Solved

SQL question

Posted on 1998-05-04
11
138 Views
Last Modified: 2010-04-06
I want to do the following:

var list:string;
  begin

list:='("word1","word2"')'

query1.close;
query1.sql.clear;
query1.sql.add('select * from table1 where attribute IN list');

So the the In statement must use word1 en word2 to run the query.But the words are in the string variable.

Can somebody help me?
0
Comment
Question by:petereilering
  • 4
  • 4
  • 3
11 Comments
 
LVL 1

Author Comment

by:petereilering
Comment Utility
Edited text of question
0
 
LVL 1

Author Comment

by:petereilering
Comment Utility
I am using Delphi 2.0 and I have tried parambyname
0
 
LVL 5

Accepted Solution

by:
julio011597 earned 500 total points
Comment Utility
Have you tried:

query1.sql.add('select * from table1 where attribute IN '+ list);

Feel free to ask more.

-julio
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
Hi peterreilering,

SELECT *
FROM CLIENTS C
WHERE (C.ACCT_FirstName IN ('word1','word2'))

Does this work?

0
 
LVL 5

Expert Comment

by:julio011597
Comment Utility
BTW, that is NOT a parametrized query... so the "feel free to ask more" :)
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
Hi all,

Julio are you sure your code works? If so, I've learned something more today....

Otherwise we've to create the string ourselfs :

var SQLString :String;

begin
 SQLString := 'where attribute IN ('
 SQLString := SQLString + ''''+ 'Word1'+ '''';
 SQLString := SQLString + ''''+ 'Word2'+ '''';
end;

Offcourse last would be better in a loop .....

for i := 0 to list.Count-1 do begin
 SQLString := SQLString + ''''+ List.Strings[i]+ '''';
end;

Don't forget to close it : SQLString := SQLString + ')';

And then :

query1.close;
    query1.sql.clear;
    query1.sql.add('Select *');
   query1.sql('from table1');
    query1.sql.add(SQLString);

Regards, ZiF.
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
Ok, this is a working method too, but if julio's code works, that one is better offcourse! :


var LISTATTRIBUTES : TStringList;
    i : integer;
    SQLSTRING : String;
begin
 LISTATTRIBUTES := TStringList.Create;
 with LISTATTRIBUTES do begin
  Clear;
  Add('Word1');
  Add('Word2');
 end;
 SQLString := '';
 SQLString := 'Where ATTRIBUTES IN (';
 for i:= 0 to LISTATTRIBUTES.COUNT-1 do begin
  SQLString := SQLString + '''' + LISTATTRIBUTES.Strings[i]+''''+',';
 end;
 SQLString[Length(SQLString)]:= ')';
 query1.sql.clear;
  query1.sql.add('Select *');
  query1.sql('from table1');
  query1.sql.add(SQLString);
 LISTATTRIBUTES.Free;
end;

Regards, ZiF.
0
 
LVL 5

Expert Comment

by:julio011597
Comment Utility
Why shouldn't that work? I mean, Add() takes a String parameter, doesn't it?!

BTW, Zif, i wander if 'peter' is actually looking for something like your method - which is surely more general than mine - rather than a parametrized query...
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
Hi Julio, correct Add() takes a string, but I thought that he didn't meant list with just a string... I mean 500 points?.... I thought he meant with list a TStringList or something likt that... Regards, ZiF.
0
 
LVL 5

Expert Comment

by:julio011597
Comment Utility
Right; indeed, IMO, this 500 points are just too much.
But where's petereilering? It seems to be his turn.
0
 
LVL 1

Author Comment

by:petereilering
Comment Utility
Julio excelent answer it works
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now