Board index » delphi » SQL: Partial matches for query

SQL: Partial matches for query

When running an SQL, what syntax do you use to look for items that are
'similar' to a search string - eg. I want to look for all names starting
with 'Go'.  I have tried Go.., Go*, Go??? and nothing seems to work!

--Derek--
                                                      dho...@csir.co.za
                                               No opinions. Just facts.
                           http://www.cs.wits.ac.za/faq/sf/sfsafaq.html
                        "One warp core breach can really ruin your day."

 

Re:SQL: Partial matches for query


Quote
Derek wrote:

> When running an SQL, what syntax do you use to look for items that are
> 'similar' to a search string - eg. I want to look for all names starting
> with 'Go'.  I have tried Go.., Go*, Go??? and nothing seems to work!

> --Derek--
>                                                       dho...@csir.co.za
>                                                No opinions. Just facts.
>                            http://www.cs.wits.ac.za/faq/sf/sfsafaq.html
>                         "One warp core breach can really ruin your day."

Doesn't SQL come from IBM Mainframe world where the wildcard character
is % (percent) and I think there is another one for a single character
the _(underscore) so

Where Dept Like 'G%'  //gets all depts which start with G
Where Dept like '%G%' //gets all depts that have a G in the name
Where Dept like 'G_'  //gets all two letter depts starting with G

Hope this helps, I know it's hard to find

Dave Joyce

Re:SQL: Partial matches for query


Derek

try...

fieldname like 'Go%'

I think that will work

Clint Good

Re:SQL: Partial matches for query


Use the LIKE with % to get partial matches
is
SELECT * FROM CUSTOMER
WHERE CustName LIKE "GO%"

you can use the _ for single characters too
 you can even look for sequences in the middle of text to

e.g.  ContactName LIKE %John%

should find

'John Smith'
'Peter Johnson'
'Rob John Jones'

--
RCJ

Derek <dho...@csir.co.za> wrote in article
<518odi$...@peacenjoy.mikom.csir.co.za>...

Quote
> When running an SQL, what syntax do you use to look for items that are
> 'similar' to a search string - eg. I want to look for all names starting
> with 'Go'.  I have tried Go.., Go*, Go??? and nothing seems to work!

> --Derek--
>                                                       dho...@csir.co.za
>                                                No opinions. Just facts.
>                            http://www.cs.wits.ac.za/faq/sf/sfsafaq.html
>                         "One warp core breach can really ruin your day."

Re:SQL: Partial matches for query


Use the LIKE with % to get partial matches
is
SELECT * FROM CUSTOMER
WHERE CustName LIKE "GO%"

you can use the _ for single characters too
 you can even look for sequences in the middle of text to

e.g.  ContactName LIKE %John%

should find

'John Smith'
'Peter Johnson'
'Rob John Jones'

--
RCJ

Derek <dho...@csir.co.za> wrote in article
<518odi$...@peacenjoy.mikom.csir.co.za>...

Quote
> When running an SQL, what syntax do you use to look for items that are
> 'similar' to a search string - eg. I want to look for all names starting
> with 'Go'.  I have tried Go.., Go*, Go??? and nothing seems to work!

> --Derek--
>                                                       dho...@csir.co.za
>                                                No opinions. Just facts.
>                            http://www.cs.wits.ac.za/faq/sf/sfsafaq.html
>                         "One warp core breach can really ruin your day."

Other Threads