Board index » delphi » Sql Server Order Fields

Sql Server Order Fields


2004-09-10 12:28:49 AM
delphi270
I have a dbGrid with Tquery and SQL Server 7.
When a user Click in the title I order the query by the Field. Sometimes
the server raise an error saying that the ORDER BY Clause contain a field
thas is ambiguous...
I'm trying with Tfield.Origin, TField.FullName, etc... and the result is the
same...
Any Idea ?
--
Un saludo
Jaime Lloret.
ISCOPYME, S.L.
www.iscopyme.com
Administración : XXXX@XXXXX.COM
Depto. Software : XXXX@XXXXX.COM
SAT : XXXX@XXXXX.COM
 
 

Re:Sql Server Order Fields

"Jaime LLoret" <XXXX@XXXXX.COM>wrote in
Quote
I'm trying with Tfield.Origin, TField.FullName, etc... and the result
is the same...
You'll have to post the SQL.
--
Iman
 

Re:Sql Server Order Fields

Most of SQL dialects support "order by #" clause, where # is position of
column in a resultset which should be sorted. So you can costruct yours
order by clause with something like this:
'order by ' + IntToStr(AField.Index + 1).
Be aware that it will fail in case if you have calculated or lookup fields
 

Re:Sql Server Order Fields

In SQL Server works fine with ORDER BY + IntToStr(AField.Index + 1).
thanks....
"Vitali Kalinin" <XXXX@XXXXX.COM>escribi?en el mensaje
Quote
Most of SQL dialects support "order by #" clause, where # is position of
column in a resultset which should be sorted. So you can costruct yours
order by clause with something like this:
'order by ' + IntToStr(AField.Index + 1).
Be aware that it will fail in case if you have calculated or lookup fields


 

Re:Sql Server Order Fields

Jaime,
Quote
Sometimes the server raise an error saying that the ORDER BY Clause contain a field
thas is ambiguous...
I don't know whether this applies in your case, probably not, but Sql
Server will raise this complaint if you're querying on joined tables,
the column appears in both and you don't specify which instance of the
column you mean. Which you can do of course e.g. using a table alias
from the join condition ...
Cheers, Martyn
 

Re:Sql Server Order Fields

if Order by Clause it work's fine. I'have the same problem in WHERE CLAUSE
and I'haven't solution...
"Martyn Ayers" <1000threeonedottwoonesixseveneatcompuservedotcom>escribi?
en el mensaje news:XXXX@XXXXX.COM...
Quote
Jaime,

>Sometimes the server raise an error saying that the ORDER BY Clause
contain a field
>thas is ambiguous...

I don't know whether this applies in your case, probably not, but Sql
Server will raise this complaint if you're querying on joined tables,
the column appears in both and you don't specify which instance of the
column you mean. Which you can do of course e.g. using a table alias
from the join condition ...

Cheers, Martyn

 

Re:Sql Server Order Fields

Jaime LLoret writes:
Quote
if Order by Clause it work's fine. I'have the same problem in WHERE CLAUSE
and I'haven't solution...
You should use meaningful table aliases in most cases.
i.e.,
Select t1.tblID as t1_id, t2.*
from MyTable t1, MyTable t2
where t1.tblid = t2.tblid
..especially if you have a bunch of "star" field sets.
I usually use a 1-3 char mnenomic for the table name.