Solved

SQL question

Posted on 1998-05-04
11
146 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
11 Comments
 
LVL 1

Author Comment

by:petereilering
ID: 1341186
Edited text of question
0
 
LVL 1

Author Comment

by:petereilering
ID: 1341187
I am using Delphi 2.0 and I have tried parambyname
0
 
LVL 5

Accepted Solution

by:
julio011597 earned 500 total points
ID: 1341188
Have you tried:

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

Feel free to ask more.

-julio
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:ZifNab
ID: 1341189
Hi peterreilering,

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

Does this work?

0
 
LVL 5

Expert Comment

by:julio011597
ID: 1341190
BTW, that is NOT a parametrized query... so the "feel free to ask more" :)
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1341191
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
ID: 1341192
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
ID: 1341193
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
ID: 1341194
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
ID: 1341195
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
ID: 1341196
Julio excelent answer it works
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

696 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