Board index » delphi » SQL Params Problems - HELP !

SQL Params Problems - HELP !

Please, please, please can anybody tell me why this piece of SQL
stored in a TQuery works :

SELECT DISTINCT TableOut.Brick,TableOut.Name,TableOut.Mind,TableOut."Nearest x",Tableout."Nearest
y"
FROM TableOut LEFT JOIN TableIn ON TableOut.Brick = TableIn.Brick  WHERE ((TableIn.Brick Is Null)
AND (TableOut.mind >=0) AND (TableOut.mind <=2000))
    -----------------------------------------------

whereas an attempt to use parameters thus :

SELECT DISTINCT TableOut.Brick,TableOut.Name,TableOut.Mind,TableOut."Nearest x",Tableout."Nearest
y"
FROM TableOut LEFT JOIN TableIn ON TableOut.Brick = TableIn.Brick  WHERE ((TableIn.Brick Is Null)
AND (TableOut.mind >=:MinDist) AND (TableOut.mind <=:MaxDist))
    ----------------------------------------------------------

doesn't work ?

I've set up the parameters as follows :

Query1.Close;
Query1.Prepare;
Query1.ParamByName('MinDist').AsInteger := 0;
Query1.ParamByName('MaxDist').AsInteger := 2000;
Query1.Open;

But I always get zero records returned.

This is driving me insane, please help before they take me away to the
funny farm !

Thanks in advance.

P.S. I'm using Delphi 2.0.

---
Ian Whitcombe

"Theres no more ignoring, you're pretty, but you're boring" - B.Bragg

 

Re:SQL Params Problems - HELP !


Ian Whitcombe <IWhitco...@ma.ccngroup.com> wrote in article
<722567528...@ma.ccngroup.com>...

Quote

> Please, please, please can anybody tell me why this piece
of SQL
> stored in a TQuery works :

> SELECT DISTINCT

TableOut.Brick,TableOut.Name,TableOut.Mind,TableOut."Nearest
x",Tableout."Nearest
Quote
> y"
> FROM TableOut LEFT JOIN TableIn ON TableOut.Brick =

TableIn.Brick  WHERE ((TableIn.Brick Is Null)
Quote
> AND (TableOut.mind >=0) AND (TableOut.mind <=2000))
>     -----------------------------------------------

> whereas an attempt to use parameters thus :

> SELECT DISTINCT

TableOut.Brick,TableOut.Name,TableOut.Mind,TableOut."Nearest
x",Tableout."Nearest
Quote
> y"
> FROM TableOut LEFT JOIN TableIn ON TableOut.Brick =

TableIn.Brick  WHERE ((TableIn.Brick Is Null)
Quote
> AND (TableOut.mind >=:MinDist) AND (TableOut.mind
<=:MaxDist))

----------------------------------------------------------
Quote

> doesn't work ?

> I've set up the parameters as follows :    

> Query1.Close;
> Query1.Prepare;
> Query1.ParamByName('MinDist').AsInteger := 0;
> Query1.ParamByName('MaxDist').AsInteger := 2000;
> Query1.Open;

> But I always get zero records returned.

Ian,

Try putting Query1.Prepare after the parameters
substitution

HTH
Peter

Other Threads