Re: Substring queries, shouldn't this be easy?
  Home FAQ Contact Sign in
microsoft.public.fox.vfp.queriessql only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: Substring queries, shouldn't this be easy?         

Group: microsoft.public.fox.vfp.queriessql · Group Profile
Author: Bernhard Sander
Date: Sep 11, 2008 06:36

Hi Mark,
> I'm sorry if it was confusing, I think these are the relevant parts
> of the tables.
>
> Yes, they're all strings. Telephone numbers, numerics only, not that
> it matters I think.
>
> The numbers in the tariff table are strings, just numbers.
> The tariff table has numbers in it like "0871", or "079523". They're
> not all the same length so "LEFT" and "SUBSTR" and the like aren't
> easily used..
>
> And the calls table has telephone numbers like "01234566789",
> "0871233454".

SELECT Numbers.number, Tariffs.code ;
FROM Numbers LEFT OUTER JOIN Tariffs ON Numbers.number = trim(Tariffs.number) ;
WHERE !empty(Tariffs.number)

This works in pure Foxpro, not in other SQL dialects.
In Foxpro, an expression like this:
longString = shortString
returns .T., when the longString at the left side starts with shortString on the
right side of =

A more complete (but not necessary in Foxpro) would be:
SELECT Numbers.number, Tariffs.code ;
FROM Numbers LEFT OUTER JOIN Tariffs ON ;
left(Numbers.number, len(trim(Tariffs.number)) = trim(Tariffs.number) ;
WHERE !empty(Tariffs.number)

LEFT OUTER JOIN returns .NULL. as Tariffs.code for every row in Numbers where
there is no matching row in Tariffs.

You will get unexpected results, if there are number entries in TARIFF like
087
0871
since the first entry will also match the telefon numbers that start with 0871

Regards
Bernhard Sander
no comments
diggit! del.icio.us! reddit!

RELATED THREADS
SubjectArticles qty Group
SUBSTRING in query of queriesmacromedia.coldfusion.cfml_general_discussion ·