M
MK
Hi,
I need to keep this query as 2 self joins; the Where statement is longer than
shown and recursively queries itself to enusre that a store has not already been used. Have just realized that line 2 of the where statement is not filtering properly,
and is allowing 2 stores to be equal.
Am I missing something ?
Thanks,
Mike
PARAMETERS [City] Text ( 255 );
INSERT INTO TEST3 ( COUNTY, STORE, ACV1, CITY1, STORE2, ACV2, CITY2, STORE3, ACV3, CITY3 )
SELECT TOP 1 E1.COUNTY, E1.STR AS STORE, E1.ACV, E1.CITY AS CITY1, E2.STR AS STORE2, E2.ACV AS ACV2, E2.CITY AS CITY2, E3.STR AS STORE3, E3.ACV AS ACV3, E3.CITY AS CITY3
FROM DATA1 AS E1, DATA1 AS E2, DATA1 AS E3
WHERE ( E1.[CITY]=[City] AND E2.[CITY]=[City] AND E3.[CITY]=[City] ) AND
( E1.[STR]<> E2.[STR] And E1.[STR]<> E3.[STR] And E2.[STR]<> E3.[STR] ) ;
I need to keep this query as 2 self joins; the Where statement is longer than
shown and recursively queries itself to enusre that a store has not already been used. Have just realized that line 2 of the where statement is not filtering properly,
and is allowing 2 stores to be equal.
Am I missing something ?
Thanks,
Mike
PARAMETERS [City] Text ( 255 );
INSERT INTO TEST3 ( COUNTY, STORE, ACV1, CITY1, STORE2, ACV2, CITY2, STORE3, ACV3, CITY3 )
SELECT TOP 1 E1.COUNTY, E1.STR AS STORE, E1.ACV, E1.CITY AS CITY1, E2.STR AS STORE2, E2.ACV AS ACV2, E2.CITY AS CITY2, E3.STR AS STORE3, E3.ACV AS ACV3, E3.CITY AS CITY3
FROM DATA1 AS E1, DATA1 AS E2, DATA1 AS E3
WHERE ( E1.[CITY]=[City] AND E2.[CITY]=[City] AND E3.[CITY]=[City] ) AND
( E1.[STR]<> E2.[STR] And E1.[STR]<> E3.[STR] And E2.[STR]<> E3.[STR] ) ;