anorthcote
Programmer
Hi,
I have the following data in a table
I'm writing a stored procedure to return these items grouped by category and sub category. In my example above 'Fans' and 'Pumps' are sub categories of 'Air Conditioning'. My stored procedure adds two spaces to the beginning of the sub category descriptions to help the user identify them as sub categories.
My question is - how can I sort the table into alphabetical order first by description where SubCatID is 0 then by description where SubCatID is not zero but still keeping rows where CatID is the same together.
Example
Does this make sense and can anyone help?
I have the following data in a table
Code:
ID CatID SubCatID Description
7 7 0 Sprinklers
8 8 0 Intruder Alarm
9 9 0 Air Conditioning
22 9 1 Fans
23 9 2 Pumps
I'm writing a stored procedure to return these items grouped by category and sub category. In my example above 'Fans' and 'Pumps' are sub categories of 'Air Conditioning'. My stored procedure adds two spaces to the beginning of the sub category descriptions to help the user identify them as sub categories.
My question is - how can I sort the table into alphabetical order first by description where SubCatID is 0 then by description where SubCatID is not zero but still keeping rows where CatID is the same together.
Example
Code:
ID CatID SubCatID Description
9 9 0 Air Conditioning
22 9 1 Fans
23 9 2 Pumps
8 8 0 Intruder Alarm
7 7 0 Sprinklers
Does this make sense and can anyone help?