FoxProProgrammer
Programmer
Hi!
I wrote a Query whose results might look like this:
Part Number Description
123 ABC 1
456 ABC 2
789 ABC 5
873 ABC 10
329 BCD 2
234 BCD 3
897 BCD 21
The Query is:
The Query works fine when used alone.
If ORDER BY is simply set to Description, the results would look like this:
Part Number Description
123 ABC 1
873 ABC 10
456 ABC 2
789 ABC 5
329 BCD 2
897 BCD 21
234 BCD 3
Now I want to include the query above in a UNION as follows:
The results are sorting by Part Number like this:
Part Number Description
123 ABC 1
234 BCD 3
329 BCD 2
456 ABC 2
789 ABC 5
873 ABC 10
888 CAP 0.1UF
897 BCD 21
I want the results to be sorted by Description as follows:
Part Number Description
123 ABC 1
456 ABC 2
789 ABC 5
873 ABC 10
329 BCD 2
234 BCD 3
897 BCD 21
888 CAPACITOR 0.1UF
The ORDER BY in the first part of the UNION isn't working, and I don't understand why the results are sorted by Part Number. Any idea what I'm doing wrong?
Thanks very much.
dz
I wrote a Query whose results might look like this:
Part Number Description
123 ABC 1
456 ABC 2
789 ABC 5
873 ABC 10
329 BCD 2
234 BCD 3
897 BCD 21
The Query is:
Code:
SELECT tbl_X.PN AS [Part Number], tbl_X.Description FROM tbl_X
ORDER BY IIf(IsNumeric(Mid([Description],2,1)),Left([Description],1),IIf(IsNumeric(Mid([Description],3,1)),Left([Description],2),Left([Description],3))), Val(IIf(IsNumeric(Mid([Description],2,1)),Mid([Description],2),IIf(IsNumeric(Mid([Description],3,1)),Mid([Description],3),Mid([Description],4))));
The Query works fine when used alone.
If ORDER BY is simply set to Description, the results would look like this:
Part Number Description
123 ABC 1
873 ABC 10
456 ABC 2
789 ABC 5
329 BCD 2
897 BCD 21
234 BCD 3
Now I want to include the query above in a UNION as follows:
Code:
SELECT tbl_X.PN AS [Part Number], tbl_X.Description FROM tbl_X
ORDER BY IIf(IsNumeric(Mid([Description],2,1)),Left([Description],1),IIf(IsNumeric(Mid([Description],3,1)),Left([Description],2),Left([Description],3))), Val(IIf(IsNumeric(Mid([Description],2,1)),Mid([Description],2),IIf(IsNumeric(Mid([Description],3,1)),Mid([Description],3),Mid([Description],4))))
UNION
SELECT tbl_Y.PN AS [Part Number], tbl_Y.Description
FROM tbl_Y;
The results are sorting by Part Number like this:
Part Number Description
123 ABC 1
234 BCD 3
329 BCD 2
456 ABC 2
789 ABC 5
873 ABC 10
888 CAP 0.1UF
897 BCD 21
I want the results to be sorted by Description as follows:
Part Number Description
123 ABC 1
456 ABC 2
789 ABC 5
873 ABC 10
329 BCD 2
234 BCD 3
897 BCD 21
888 CAPACITOR 0.1UF
The ORDER BY in the first part of the UNION isn't working, and I don't understand why the results are sorted by Part Number. Any idea what I'm doing wrong?
Thanks very much.
dz