A
Albert Frausto
I have one table that contains the parent / child data for vehicle
makes/models. I'm trying to create the following results which will populate
a listbox. Here's the table:
Table: directory_categories
category_id category_name category_id_parent
1 Acura NULL
2 Ford NULL
3 GM NULL
4 Model T 2
5 Model A 2
6 Truck 2
Target results,
catsub_id catsub_name
1 Acura
2 Ford
4 Ford > Model T
5 Ford > Model A
6 Ford > Truck
3 GM
I've tried the following query but it's not quite giving me the correct
results.
SELECT C1.category_id AS catSub_ID,
C1.category_name+Nz('->'+C2.category_name,'') AS CatSub_Name
FROM directory_categories AS C1 LEFT JOIN directory_categories AS C2 ON
C1.category_id_parent = C2.category_id
ORDER BY C1.category_name;
I get the following with the above query:
cat_SubID cat_SubName
1 Acura
2 Ford
3 GM
4 Model T > Ford (This should be Ford -> Model T)
5 Model A > Ford (This should be Ford -> Model A)
6 Truck > Ford (This should be Ford -> Truck)
Thank you to everyone for their help in advance.
makes/models. I'm trying to create the following results which will populate
a listbox. Here's the table:
Table: directory_categories
category_id category_name category_id_parent
1 Acura NULL
2 Ford NULL
3 GM NULL
4 Model T 2
5 Model A 2
6 Truck 2
Target results,
catsub_id catsub_name
1 Acura
2 Ford
4 Ford > Model T
5 Ford > Model A
6 Ford > Truck
3 GM
I've tried the following query but it's not quite giving me the correct
results.
SELECT C1.category_id AS catSub_ID,
C1.category_name+Nz('->'+C2.category_name,'') AS CatSub_Name
FROM directory_categories AS C1 LEFT JOIN directory_categories AS C2 ON
C1.category_id_parent = C2.category_id
ORDER BY C1.category_name;
I get the following with the above query:
cat_SubID cat_SubName
1 Acura
2 Ford
3 GM
4 Model T > Ford (This should be Ford -> Model T)
5 Model A > Ford (This should be Ford -> Model A)
6 Truck > Ford (This should be Ford -> Truck)
Thank you to everyone for their help in advance.