Re:Sort a query
Hi Ben,
As Bill said it is not possible. However, I never use Parameters as you
understand them but in fact I use text substitution.
So to take your example SELECT * FROM Table ORDER BY :FieldParam
My function call would be something like
MyExecuteQuery(QueryString, Parameters, NoParameters)
where Query string would be something like
LPSTR Query = SELECT * FROM #0 ORDER BY #1
LPSTR Parameters[];
Parameters[0] = "TABLE1"
Parameters[1] = "A_FIELD_NAME"
and in the case above NoParameters = 2
All the ExecuteQuery() has to do now is to replace *all* occurrences of #0
and #1 with the values in the Parameters array (you might use them a number
of times). This method works for both SQL and QBE scripts and probably for
others I do not know about. I have used this for years know without fail.
Leslie.
"Ben" <
XXXX@XXXXX.COM >wrote in message
Quote
Hello,
I have a question..
I use a TQuery object to query a database and I want to sort the results
of
my "SELECT...".
If I add "ORDER BY..." in my query, can I declare a param for the name of
the field I want to sort by ?
For example, the propriety SQL of my TQuery object could be :
"SELECT * FROM Table ORDER BY :FieldParam"
If it's possible, which "DataType" must I choice for the param ?
And else, what's the best solution to change easily the sort of my query ?
I
want to show the result in a TDBGrid, and I want to let the user of my
application change the field to sort by dynamically.
Thanks for your help.
Ben
{smallsort}