I have a table like so:
CREATE TABLE #Categories (CategoryText VARCHAR(50), CategoryUrl VARCHAR(50), SubCategoryText VARCHAR(50), SubCategoryUrl VARCHAR(50))
INSERT INTO #Categories SELECT 'Lighting', 'http://lighting.com', 'Chandeliers', 'http://chandeliers.com'
INSERT INTO #Categories SELECT 'Lighting', 'http://lighting.com', 'Lamps', 'http://lamps.com'
INSERT INTO #Categories SELECT 'Hardware', 'http://hardware.com', 'Hooks', 'http://hooks.com'
INSERT INTO #Categories SELECT 'Hardware', 'http://hardware.com', 'Hinges', 'http://hinges.com'
which looks like:
CategoryText CategoryUrl SubCategoryText SubCategoryUrl
-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- --------------------------------------------------
Lighting http://lighting.com Chandeliers http://chandeliers.com
Lighting http://lighting.com Lamps http://lamps.com
Hardware http://hardware.com Hooks http://hooks.com
Hardware http://hardware.com Hinges http://hinges.com
How would I dynamically display the data as follows:
Type Text Url
----------- -------------------------------------------------- --------------------------------------------------
Category Lighting http://lighting.com
SubCategory Chandeliers http://chandeliers.com
SubCategory Lamps http://lamps.com
Category Hardware http://hardware.com
SubCategory Hinges http://hinges.com
SubCategory Hooks http://hooks.com
I also need to retain the correct order of categories and subcategories.
UNPIVOT came to mind, but I don't see how I can apply it here as the data structure/requirements are different than most examples out there.
Any help is appreciated.