Board index » delphi » TQuery.SQL.Param Question

TQuery.SQL.Param Question

Hello

I am Using D3 with Paradox 7 tables.
I am wondering why the following Query with Params gives me an invalid token
message.

Select *
From File1
Order by :ColName

:ColName parameter is assigned DBGrid1.FieldName using ParamByName.
If your wondering, these SQL statements are to sort a DBGrid by clicking on
the column heading.
Does parameter passing in BDE/Local SQL only work if you pass actual Field
Values or can you use it for straight string substitution.

Thanks in advance :-)

P.S. I've got this working I just delete the last line using SQL.Delete(2)
and the use SQL.add('Order by '+Column.FieldName);.
       Just wondering why the SQL param statements don't work, would save a
lot of headaches.

 

Re:TQuery.SQL.Param Question


Quote
Neil Odegard wrote:
> Select *
> From File1
> Order by :ColName

> Does parameter passing in BDE/Local SQL only work if you pass actual Field
> Values or can you use it for straight string substitution.

You misinterpret parameter passing. Parameter passing is for filling
constants in an SQL statement using a host variable. Like

Select * from Table1
Where AKey = :AKey

will translate to

Select * from Table1
Where AKey = 35

when you set host variable AKey to 35.

It will not change the text of your SQL, nor will your SQL be
translated  again.

The other way you suggested is the correct way.

HTH

Re:TQuery.SQL.Param Question


Thanks HTH, that what I figured, but had to know for sure.

Quote
Menno Holscher <mhols...@Killspam.wxs.nl> wrote in message

news:374474F0.5CB0@Killspam.wxs.nl...
Quote
> Neil Odegard wrote:

> > Select *
> > From File1
> > Order by :ColName

> > Does parameter passing in BDE/Local SQL only work if you pass actual
Field
> > Values or can you use it for straight string substitution.

> You misinterpret parameter passing. Parameter passing is for filling
> constants in an SQL statement using a host variable. Like

> Select * from Table1
> Where AKey = :AKey

> will translate to

> Select * from Table1
> Where AKey = 35

> when you set host variable AKey to 35.

> It will not change the text of your SQL, nor will your SQL be
> translated  again.

> The other way you suggested is the correct way.

> HTH

Other Threads