SQL Question
am 03.11.2009 18:17:52 von Phibee NOC
Hi
i request a small help for know if it's possible.
Anyone know if they have a Sql request for
search the best value at one information:
Sample:
i have a table with:
ID int 5
Chaine int 16
and this entry:
1 12345
2 123
3 12
i am search a request in "WHERE" :
Chaine LIKE '123456789' and if he don't have into the database,
he test Chaine LIKE '12345678' etc ..
and when he arrive at 12345, he sent the ID information
thanks for your help
(PS: i use Perl for extract data)
Jerome
Sorry for my english
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org
RE: SQL Question
am 03.11.2009 19:54:38 von Martin Gainty
--_75e3d941-9489-4494-baf9-6ac96e2c33c9_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
you'll need to write a recursive routine to call the same sql statement
and iterate from the largest value and attenuate that value by 1 each time
# file: test.pl been a few years but this should work
#initialize your variable that you will attenuate
my $global =3D "9876543210"=3B
#number of rows actually returned
my $affectedrows=3D0=3B
#the offset for constructing the next global variable
my $offset=3D10=3B
#stay in this loop until we have successful result
#OR there are no rows found
while($affectedrows==0)
{
do_it()=3B
}
if($affectedrows==99) print("no rows found")=3B
sub do_it
{
# DEFINE A MySQL QUERY
$myquery =3D "SELECT * FROM $tablename where column1=3D$global"=3B
$execute =3D $connect->query($myquery)=3B
#attenuate 1 character off
$offset =3D $offset -1=3B
$global =3D substr($global=2C 0=2C $offset)=3B
#test for global having no value
if ($offset==0) $affectedrows=3D99=3B
else $affectedrows =3D $execute->affectedrows($myquery)=3B
}
http://www.tizag.com/perlT/perlmysqlquery.php
(notice the site is written in PHP)
Martin Gainty=20
______________________________________________=20
Verzicht und Vertraulichkeitanmerkung/Note de d=E9ni et de confidentialit=
=E9
=20
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaeng=
er sein=2C so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiter=
leitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient l=
ediglich dem Austausch von Informationen und entfaltet keine rechtliche Bin=
dungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen w=
ir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut =EAtre privil=E9gi=E9. Si vous n'=EAtes=
pas le destinataire pr=E9vu=2C nous te demandons avec bont=E9 que pour sat=
isfaire informez l'exp=E9diteur. N'importe quelle diffusion non autoris=E9e=
ou la copie de ceci est interdite. Ce message sert =E0 l'information seule=
ment et n'aura pas n'importe quel effet l=E9galement obligatoire. =C9tant d=
onn=E9 que les email peuvent facilement =EAtre sujets =E0 la manipulation=
=2C nous ne pouvons accepter aucune responsabilit=E9 pour le contenu fourni=
..
> Date: Tue=2C 3 Nov 2009 18:17:52 +0100
> From: noc@phibee.net
> To: mysql@lists.mysql.com
> Subject: SQL Question
>=20
> Hi
>=20
> i request a small help for know if it's possible.
>=20
> Anyone know if they have a Sql request for
> search the best value at one information:
>=20
> Sample:
>=20
> i have a table with:
>=20
> ID int 5
> Chaine int 16
>=20
> and this entry:
>=20
> 1 12345
> 2 123
> 3 12
>=20
>=20
> i am search a request in "WHERE" :
>=20
> Chaine LIKE '123456789' and if he don't have into the database=2C
> he test Chaine LIKE '12345678' etc ..
> and when he arrive at 12345=2C he sent the ID information
>=20
> thanks for your help
>=20
> (PS: i use Perl for extract data)
> Jerome
> Sorry for my english
>=20
> --=20
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=3Dmgainty@hotmail.c=
om
>=20
=20
____________________________________________________________ _____
Bing brings you maps=2C menus=2C and reviews organized in one place.
http://www.bing.com/search?q=3Drestaurants&form=3DMFESRP&pub l=3DWLHMTAG&cre=
a=3DTEXT_MFESRP_Local_MapsMenu_Resturants_1x1=
--_75e3d941-9489-4494-baf9-6ac96e2c33c9_--