Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL question

Posted on 1998-05-04
11
Medium Priority
?
158 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 2000 total points
ID: 1341188
Have you tried:

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

Feel free to ask more.

-julio
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

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…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

604 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