私は次のようなテーブルを持っています:
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'
次のようになります。
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
次のようにデータを動的に表示するにはどうすればよいですか。
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
また、カテゴリとサブカテゴリの正しい順序を維持する必要もあります。
UNPIVOT が頭に浮かびましたが、データ構造/要件が他のほとんどの例とは異なるため、ここでどのように適用できるかわかりません。
どんな助けでも大歓迎です。