I am building Parameterized dynamic SQL queries (not stored procedures) in a classic ASP application (using SQL Server 2005).When I try to pass a parameter to the " ORDER BY " clause, I get error "Application uses a value of the wrong type for the current operation". Below is example. What am I doing wrong? Thank you in advance.

While not first defining the parameter is less desireable technique, it does work when the query assigns the parameter to a specific column like this: strSQL="SELECT ObjectNum, ObjName FROM qryVisMultiProcess WHERE ObjName = ?;"

But it fails when the query does not have a specific column to assign the parameter to, like this. strSQL="SELECT ObjectNum, ObjName FROM qryVisMultiProcess WHERE ObjectNum >= 0 ORDER BY ?;"

So, if I predefine it, what would be the type and size for this parameter? objCmd.Parameters.Append = objCmd.CreateParameter(fld1, type??, adParamInput, size?? , fld1)

I tried using the data type of the column being passed as below, but it still failed:

fld1="ObjectNum" ' this column is an integer typestrSQL="SELECT ObjectNum, ObjName FROM qryVisMultiProcess ORDER BY ?;"