15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


SQL Like Statement ?

Heiko Schwarz -- hschwarz@fvkma.tu-graz.ac.at
Thursday, November 28, 1996

Environment: MSVC 1.52, Windows 3.11, ODBC Driver for Access 2.0

I've made a little application which makes some SQL-Queries on a database 
with the help of MFC.

If I try something like:
    "SELECT * FROM Table WHERE Col LIKE 'Te*'"
I get nothing. But there are entries in the table that begin with 'Te' in
column Col.

The SQL-Query only works for statements like (only for exact matches):
    "SELECT * FROM Table WHERE Col = 'Test'"

Does anyone know what's wrong ?

-  Heiko "The Eraser" Schwarz      \__\/__/ Tutor for BA&CG and CO1  -
  Telematik-Student at             / _  _ \           Pig_Ben on IRC
 Graz, University of Technology   | (O)(O) |  root on my LINUX-Box ;)
 ______________________________.OOOo__oo__oOOO.______________________
| ftp://fvkma.tu-graz.ac.at/pub/star-trek/                           |
| http://fvkma.tu-graz.ac.at/star-trek/  or  http://fvkma/~hschwarz/ |
|_ hschwarz@fvkma.tu-graz.ac.at _.oooO___Oooo.__________ Finger4PGP _|
                                 (   )   (   )
                                  \ (     ) /
                                   \_)   (_/
                                    





Ray Barley -- barley@rdaconsultants.com
Saturday, November 30, 1996

The percent character (%) matches 0 or more of any character; the
underscore character (_) matches 1 character.  Just replace the '*' with
'%' and you should be ok.

>----------
>From: 	Heiko Schwarz[SMTP:hschwarz@fvkma.tu-graz.ac.at]
>Sent: 	Thursday, November 28, 1996 1:32 PM
>To: 	mfc-l
>Subject: 	SQL Like Statement ?
>
>Environment: MSVC 1.52, Windows 3.11, ODBC Driver for Access 2.0
>
>I've made a little application which makes some SQL-Queries on a database 
>with the help of MFC.
>
>If I try something like:
>    "SELECT * FROM Table WHERE Col LIKE 'Te*'"
>I get nothing. But there are entries in the table that begin with 'Te' in
>column Col.
>
>The SQL-Query only works for statements like (only for exact matches):
>    "SELECT * FROM Table WHERE Col = 'Test'"
>
>Does anyone know what's wrong ?
>
>-  Heiko "The Eraser" Schwarz      \__\/__/ Tutor for BA&CG and CO1  -
>  Telematik-Student at             / _  _ \           Pig_Ben on IRC
> Graz, University of Technology   | (O)(O) |  root on my LINUX-Box ;)
> ______________________________.OOOo__oo__oOOO.______________________
>| ftp://fvkma.tu-graz.ac.at/pub/star-trek/                           |
>| http://fvkma.tu-graz.ac.at/star-trek/  or  http://fvkma/~hschwarz/ |
>|_ hschwarz@fvkma.tu-graz.ac.at _.oooO___Oooo.__________ Finger4PGP _|
>                                 (   )   (   )
>                                  \ (     ) /
>                                   \_)   (_/
>                                    
>
>
>



Colin Angus Mackay -- colin.angus.mackay@dial.pipex.com
Saturday, November 30, 1996

Try something like

"SELECT * FROM Table WHERE Col LIKE 'Te%'"

for zero or more possibilities or

"SELECT * FROM Table WHERE Col LIKE 'Te_'"

for exactly a one character wildcard.

Hope this helps,

Colin Angus Mackay



> Environment: MSVC 1.52, Windows 3.11, ODBC Driver for Access 2.0
> 
> I've made a little application which makes some SQL-Queries on a database 
> with the help of MFC.
> 
> If I try something like:
>     "SELECT * FROM Table WHERE Col LIKE 'Te*'"
> I get nothing. But there are entries in the table that begin with 'Te' in
> column Col.
> 
> The SQL-Query only works for statements like (only for exact matches):
>     "SELECT * FROM Table WHERE Col = 'Test'"
> 
> Does anyone know what's wrong ?
> 
> -  Heiko "The Eraser" Schwarz      \__\/__/ Tutor for BA&CG and CO1  -
>   Telematik-Student at             / _  _ \           Pig_Ben on IRC
>  Graz, University of Technology   | (O)(O) |  root on my LINUX-Box ;)
>  ______________________________.OOOo__oo__oOOO.______________________
> | ftp://fvkma.tu-graz.ac.at/pub/star-trek/                           |
> | http://fvkma.tu-graz.ac.at/star-trek/  or  http://fvkma/~hschwarz/ |
> |_ hschwarz@fvkma.tu-graz.ac.at _.oooO___Oooo.__________ Finger4PGP _|
>                                  (   )   (   )
>                                   \ (     ) /
>                                    \_)   (_/
>



Norman Widders -- winspace@void.hell.net
Monday, December 02, 1996

In reply to the honourable 'hschwarz@fvkma.tu-graz.ac.at' who said:

> If I try something like:
>     "SELECT * FROM Table WHERE Col LIKE 'Te*'"
> I get nothing. But there are entries in the table that begin with 'Te' in
> column Col.
> 
> The SQL-Query only works for statements like (only for exact matches):
>     "SELECT * FROM Table WHERE Col = 'Test'"
> 
> Does anyone know what's wrong ?


try using the percent symbol for wildcards, ie LIKE '%TE%' or LIKE 'TE%'
depending on what you require.



+------------------------------------------------------------+
|                                                            |
|   _/_/         _/_/     _/_/_/_/_/_/      _/_/_/_/_/_/     |
|   _/_/        _/_/     _/_/_/            _/_/              |
|    _/_/ _/_/ _/_/      _/_/              _/_/_/            |
|     _/_/_/_/_/_/       _/_/_/            _/_/              |
|      _/_/  _/_/         _/_/_/_/_/_/      _/_/_/_/_/_/     |
|                                                            |
|                                                            |
| winspace@geko.net.au - Software Engineering in C++ and SQL |
+------------------------------------------------------------+






tjoen oei -- tjoen@dds.nl
Sunday, December 01, 1996

Heiko Schwarz wrote:
> 
> Environment: MSVC 1.52, Windows 3.11, ODBC Driver for Access 2.0
> 
> If I try something like:
>     "SELECT * FROM Table WHERE Col LIKE 'Te*'"
> I get nothing. But there are entries in the table that begin with 'Te' in
> column Col.

Have you tried "...LIKE 'Te%'"



Mike Morel -- mmorel@mushroomsoft.com
Sunday, December 01, 1996

Use the SQL wildcard character:
"SELECT * FROM Table WHERE Col LIKE 'Te%'"

Looking for (Col LIKE 'Te*') will find "T" in first position, "e" in the second, and "*" in the third.

Mike Morel
Mushroom Software
Home of MFC For Yourself
http://www.mushroomsoft.com


----------
From: 	Heiko Schwarz[SMTP:hschwarz@fvkma.tu-graz.ac.at]
Sent: 	Thursday, November 28, 1996 2:32 PM
To: 	mfc-l
Subject: 	SQL Like Statement ?

Environment: MSVC 1.52, Windows 3.11, ODBC Driver for Access 2.0

I've made a little application which makes some SQL-Queries on a database 
with the help of MFC.

If I try something like:
    "SELECT * FROM Table WHERE Col LIKE 'Te*'"
I get nothing. But there are entries in the table that begin with 'Te' in
column Col.

The SQL-Query only works for statements like (only for exact matches):
    "SELECT * FROM Table WHERE Col = 'Test'"

Does anyone know what's wrong ?

-  Heiko "The Eraser" Schwarz      \__\/__/ Tutor for BA&CG and CO1  -
  Telematik-Student at             / _  _ \           Pig_Ben on IRC
 Graz, University of Technology   | (O)(O) |  root on my LINUX-Box ;)
 ______________________________.OOOo__oo__oOOO.______________________
| ftp://fvkma.tu-graz.ac.at/pub/star-trek/                           |
| http://fvkma.tu-graz.ac.at/star-trek/  or  http://fvkma/~hschwarz/ |
|_ hschwarz@fvkma.tu-graz.ac.at _.oooO___Oooo.__________ Finger4PGP _|
                                 (   )   (   )
                                  \ (     ) /
                                   \_)   (_/
                                    









Jeremy H. Griffith -- jeremy@omsys.com
Sunday, December 01, 1996

On Thu, 28 Nov 1996 19:32:46 +0100 (MET), Heiko Schwarz
 wrote:

>Environment: MSVC 1.52, Windows 3.11, ODBC Driver for Access 2.0
>
>I've made a little application which makes some SQL-Queries on a database 
>with the help of MFC.
>
>If I try something like:
>    "SELECT * FROM Table WHERE Col LIKE 'Te*'"
>I get nothing. But there are entries in the table that begin with 'Te' in
>column Col.
>
>The SQL-Query only works for statements like (only for exact matches):
>    "SELECT * FROM Table WHERE Col = 'Test'"
>
>Does anyone know what's wrong ?

Sure.  SQL has different wild-card characters from DOS.  ;-)  Use:
  % instead of * for multiple characters
  _ instead of ? for single characters

so "LIKE 'Te%'" should work...

There are several more features to "LIKE" that you may want to use;
since these are extended in different ways on different DBMS's, you'd
best check the docs on the on you're using.  If you don't have those,
I have Sybase and MS SQL Server docs on hand... they support:
 [abcd] to allow any of a, b, c, or d
 [^abc] to exclude a, b, or c, allowing anything else

--Jeremy



Dong Chen -- d_chen@ix.netcom.com
Sunday, December 01, 1996

At 07:32 PM 11/28/96 +0100, you wrote:
>Environment: MSVC 1.52, Windows 3.11, ODBC Driver for Access 2.0
>
>I've made a little application which makes some SQL-Queries on a database 
>with the help of MFC.
>
>If I try something like:
>    "SELECT * FROM Table WHERE Col LIKE 'Te*'"
>I get nothing. But there are entries in the table that begin with 'Te' in
>column Col.
>

Try:
        SELECT * FROM Table WHERE Col LIKE 'Te%%'
--




Martin J. Mahoney -- mjm@PyramidLogicSystems.com
Sunday, December 01, 1996

If I remember my SQL, it has been a while, SQL uses % and instead * so the
statement should look like:

"SELECT * FROM Table WHERE Col LIKE 'Te%'"

Martin J. Mahoney

----------
> From: Heiko Schwarz 
> To: mfc-l 
> Subject: SQL Like Statement ?
> Date: Thursday, November 28, 1996 1:32 PM
> 
> Environment: MSVC 1.52, Windows 3.11, ODBC Driver for Access 2.0
> 
> I've made a little application which makes some SQL-Queries on a database

> with the help of MFC.
> 
> If I try something like:
>     "SELECT * FROM Table WHERE Col LIKE 'Te*'"
> I get nothing. But there are entries in the table that begin with 'Te' in
> column Col.
> 
> The SQL-Query only works for statements like (only for exact matches):
>     "SELECT * FROM Table WHERE Col = 'Test'"
> 
> Does anyone know what's wrong ?
> 
> -  Heiko "The Eraser" Schwarz      \__\/__/ Tutor for BA&CG and CO1  -
>   Telematik-Student at             / _  _ \           Pig_Ben on IRC
>  Graz, University of Technology   | (O)(O) |  root on my LINUX-Box ;)
>  ______________________________.OOOo__oo__oOOO.______________________
> | ftp://fvkma.tu-graz.ac.at/pub/star-trek/                           |
> | http://fvkma.tu-graz.ac.at/star-trek/  or  http://fvkma/~hschwarz/ |
> |_ hschwarz@fvkma.tu-graz.ac.at _.oooO___Oooo.__________ Finger4PGP _|
>                                  (   )   (   )
>                                   \ (     ) /
>                                    \_)   (_/
>                                     
> 



Tapas Kumar Das -- TAPADAS@docuaccess.nl
Monday, December 02, 1996


Use "SELECT * FROM Table WHERE Col LIKE 'Te%'"

Regards
<---------------------------------------------->
|Tapas Kumar Das                               |
|                                              |
|HCL BENELUX B.V                               |
|                                              |
|Deputate At:  Document Access B.V.            |
|                                              |
|Ph +31 (0)10 4402628                          |
|                                              |
|            __o                 |
|          _`\<,_                |
|           (*)/ (*)               |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 ----------
From:  owner-mfc-l[SMTP:owner-mfc-l@majordomo.netcom.com]
Sent:  Thursday, November 28, 1996 7:32 PM
To:  mfc-l
Subject:  SQL Like Statement ?

Environment: MSVC 1.52, Windows 3.11, ODBC Driver for Access 2.0

I've made a little application which makes some SQL-Queries on a database   

with the help of MFC.

If I try something like:
    "SELECT * FROM Table WHERE Col LIKE 'Te*'"
I get nothing. But there are entries in the table that begin with 'Te' in
column Col.

The SQL-Query only works for statements like (only for exact matches):
    "SELECT * FROM Table WHERE Col = 'Test'"

Does anyone know what's wrong ?

 -  Heiko "The Eraser" Schwarz      \__\/__/ Tutor for BA&CG and CO1  -
  Telematik-Student at             / _  _ \           Pig_Ben on IRC
 Graz, University of Technology   | (O)(O) |  root on my LINUX-Box ;)
 ______________________________.OOOo__oo__oOOO.______________________
| ftp://fvkma.tu-graz.ac.at/pub/star-trek/                           |
| http://fvkma.tu-graz.ac.at/star-trek/  or  http://fvkma/~hschwarz/ |
|_ hschwarz@fvkma.tu-graz.ac.at _.oooO___Oooo.__________ Finger4PGP _|
                                 (   )   (   )
                                  \ (     ) /
                                   \_)   (_/
                                      







Gerry Sweeney -- gerry@hornbill.com
Monday, December 02, 1996


Environment: MSVC 1.52, Windows 3.11, ODBC Driver for Access 2.0

The '*' is not a wild card in SQL. Use the '%' char. Try the following:-

"SELECT * FROM Table WHERE Col LIKE 'Te%'"

>I've made a little application which makes some SQL-Queries on a database
>with the help of MFC.
>
>If I try something like:
>    "SELECT * FROM Table WHERE Col LIKE 'Te*'"
>I get nothing. But there are entries in the table that begin with 'Te' in
>column Col.
>
>The SQL-Query only works for statements like (only for exact matches):
>    "SELECT * FROM Table WHERE Col = 'Test'"
>
>Does anyone know what's wrong ?


Gerry Sweeney
gerry@hornbill.com




| Вернуться в корень Архива |