Oct 23 2019 11:45 AM
I have a category list that will be added to a combo box. Here is my SQL....
SELECT tblCategoryList.Category
FROM tblCategoryList
UNION
SELECT "All"
FROM tblCategoryList
ORDER BY tblCategoryList.Category;
So the code works, my problem is that I want the added text "All" to be placed on top of the list produced. When there is a category that contains special characters it is placed on top of "All".
Oct 24 2019 09:16 AM
I would make an extrta column in the query and skip it in the combobox.
SELECT tblCategoryList.id, tblCategoryList.Category
FROM tblCategoryList
UNION
SELECT 0, "All"
FROM tblCategoryList
ORDER BY tblCategoryList.id, tblCategoryList.Category;
Greetings,
Marcel
Oct 24 2019 09:24 AM - edited Oct 24 2019 09:28 AM
Try " All" instead of "All"
However, I agree that you may have a problem here. If the table called "tblCategoryList" has a single field called "Category", then the current design is appropriate. If, on the other hand, "tblCategoryList" has an ID field for its Primary Key (using the AutoNumber), then that is the appropriate field to be used in the combo box as the bound column, while the value field, "Category" would only be displayed to users.
Oct 24 2019 10:37 AM
Sorry I posted wrong SQL before. Needs to sort better :))
SELECT iif(tblCategoryList.id=0,0,"1"& tblCategoryList.Category) as zCategory, tblCategoryList.Category
FROM tblCategoryList
UNION SELECT 0,"all"
FROM tblCategoryList
ORDER BY zcategory
With this you can skip the first column and it will work as needed.
Oct 25 2019 03:14 PM - edited Oct 25 2019 03:24 PM
SolutionThanks guys for helping me solve my issue. Here is my working code:
' SELECT tblCategoryList.Category As Category, "1" As ID
' FROM tblCategoryList
' UNION
' SELECT "All Tags", 0
' FROM tblCategoryList
' ORDER BY ID, Category;
Basically I created a row in SQL called ID and all records added from the tblCategoryList table are labeled 1 under ID. The Union adds the "All Tags" and under the ID column the row is identified with 0. Then I sort via ID and followed by Category. Now I can keep the order ascending and no matter what the "All Tags" remains on top.