?
Solved

Delphi - Paradox Query / LIKE command

Posted on 2007-03-31
15
Medium Priority
?
2,218 Views
Last Modified: 2010-04-05
Hi

I am using the LIKE SQL command in Delphi - paradox table and my query is :
Select * from
Table
where Field1 like : '%Field1%'
order by Field2,Field3
But I am not getting any result.
I read in the internet that the LIKE command cann't be used with Variables , but only with static string , is it true and if so what can i do to get the kind of search i want it in my program. what i want is if a user typed a word of a sentence i shall get the whole sentence like
sentence : ' macnhester defeated chelsea 2 to nil '
so if the user wrote defeat in the search field then he will get the previous sentence or any other matches

thanks
0
Comment
Question by:ibrobar
[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
  • 5
  • 4
  • 3
  • +2
15 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18828297
I have 2 potential ideas:
* try using * instead of %

* >where Field1 like : '%Field1%'
I assume that you meant
where Field1 like : '%defeat%'
0
 

Author Comment

by:ibrobar
ID: 18828310
Hi again

I have field called Description and the query will be :
select * from TreeData
where Description like :'%Description%'
order by date1,month1
So i am using variable cause i don't know afourse the value i am looking for

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18828409
you mean "Description" is the name of the field AND of the variable?
when/how is that variable filled?
0
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!

 
LVL 10

Expert Comment

by:dinilud
ID: 18828457
Try this

select * from TreeData
where Description like   '%'+  :Description +'%'
order by date1,month1
0
 
LVL 6

Expert Comment

by:Hardi
ID: 18828524
what if you remove the colon?
where Description like '%Description%'
0
 
LVL 2

Expert Comment

by:uaexpert
ID: 18834630
Actually this way it must work :


select * from TreeData
where Description like   '%' +  Description + '%'
order by date1,month1

but this query is just useless because the condition in WHERE clause will always return True.
It can have some sense if you will compare one field with some other field, e.g.:
WHERE Description LIKE '%' + SearchWord + '%'
(here SearchWord is another field in your table).
0
 

Author Comment

by:ibrobar
ID: 18841577
Hi

Dinilud I will try your solution today.
Uaexpert I want to choose the value of the variable field during run time cause i am doing a search during runtime  up to the user demand.
0
 
LVL 2

Accepted Solution

by:
uaexpert earned 150 total points
ID: 18841624
In such case you can use query parameter as dinilud suggested or simply create query expression "on the fly" using the value of your variable. Example:

var
  SearchWord : string; //we suppose the word entered by user is stored here
  SQL : string; //here we will store necessary SQL statement
  Query1 : TQuery;
  . . . . . .
begin
  Query1 := TQuery.Create(nil);
  Query1.DatabaseName := <Put your database name here>;
  SQL := 'select * from TreeData where Description like   ''%' + SearchWord + '%'' order by date1,month1';
  Query1.SQL := SQL;
  Query1.Open;
  //read result from Query1

0
 
LVL 6

Expert Comment

by:Hardi
ID: 18842372
Actually I don't see anything wrong with your query ibrobar.
It's just the colon is not necessary.
Does yours work if you replace LIKE with = ?
eg. where Field1 = 'macnhester defeated chelsea 2 to nil '

If it doesn't then follow uaexpert's example. You can also use the function QuotedStr for quoting.
eg.
Query1.SQL := 'select * from myTable where Description like ' +QuotedStr('%'+searchWord+'%')+ ' order by field1,field2';
0
 
LVL 6

Expert Comment

by:Hardi
ID: 18842390
Forget about QuotedStr... I still think double quotes is better =P
like uaexpert's example
0
 
LVL 6

Expert Comment

by:Hardi
ID: 18842402
btw it should be Query1.SQL.Text instead of just Query1.SQL =P
0
 
LVL 2

Expert Comment

by:uaexpert
ID: 18842784
Yes Hardi is right.
It must be:
  . . . . . .
  Query1.SQL.Text := SQL;
  . . . . . .

Actually it will be good addition to replace any single quote in SearchWord by two quotes to prevent any error if SearchWord contains quotes. Again it will not be necessary if you will use query with parameters.
0
 

Author Comment

by:ibrobar
ID: 18855534
Hi all
Sorry for the delay in replying , cause i was in my days off.
I tried this soultion :  Select * from Table where Field like : '%'+Field+'%'
but it didn't work.
I think the solution about creating a query during runtime might work , I will try it today

thanks a lot all
0
 
LVL 6

Expert Comment

by:Hardi
ID: 18855767
Why are you still using the colon... =P
If it still doesn't work, give us the full string of your query, or the code
0
 

Author Comment

by:ibrobar
ID: 18862532
Thanks UaeExpert

I tried your solution and it's working 100 percent.
thanks a lot
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

770 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