I'm trying to use the SQL code that you guys are suggesting, but I keep
getting errors... here is what I have....the fields are to be sorted by
1.) Zip-asc
2.) CART-asc
3.) Lot-asc
4.) Lot_Ord (A or D ---> determines how to sort the 5th field)
5.) DPBC- (determined by Lot_Ord)
The SQL code that I currently have is:
SELECT [Calloway In Order].LAST_NAME, [Calloway In Order].FIRST_NAME,
[Calloway In Order].ADDRESS, [Calloway In Order].CITY, [Calloway In
Order].STATE, [Calloway In Order].ZIP, [Calloway In Order].ZIP4, [Calloway In
Order].CART, [Calloway In Order].DPBC, [Calloway In Order].DPCD, [Calloway In
Order].LOT, [Calloway In Order].LOT_ORD
IIf(Lot_Ord="A",DPBC,Null) AS Expr1, IIf(Lot_ord="D",DPBC,Null) AS Expr2
FROM [Calloway In Order]
ORDER BY [Calloway In Order].ZIP, [Calloway In Order].CART, [Calloway In
Order].LOT;
IIf(Lot_Ord="A",DPBC,Null), IIf(Lot_Ord="D",DPBC,Null) DESC;
Thanks, for all your help with this!!!
Allen Browne said:
You can use IIf(), the immediate IF in a SQL statement.
But I doubt it will work in the ORDER BY clause like that.
Perhaps you could build the SQL statement dynamically in your code, once you
know which way you want the sort to go. Then apply it as the RecordSource of
your form or report, or even assign it to the SQL property of the QueryDef.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
That's what I was thinking...
But I need the query to use the 5th field to sort further depending on
what
data is in the 4th field. I know i'm making this as clear as mud, but I'm
stumped.
The only way that I would know how to do it would be some typr of "If"
statement, but I didn't know if SQL had coding for that.
:
But the 4th column could theoretically have "A" in some rows and "D" in
other rows.
I don't see how the query engine could make sense of the instruction to
sort
a column partially ascending and partially descending.
I need to sort on multiple fields within a query. There are 5 fields
that
are being sorted on, the first 3 being asc. The 4th field has an data
entered as an A or D, this telling that when field 1,2,& 3 have the
same
data, it sort either A(asc) or D(desc) depending on the 5th field.
I can get the query to run and sort on the first 3 fields, but the
application loses the sorting after this point.