我有以下cte:
WITH cte AS
(
SELECT
c.ParentIDNo,
c.Category,
c.ChildCategory,
c.WSWebProductNameIDNo,
c.IDNo,
0 AS Level,
CAST('/' + c.Category AS VARCHAR(1000)) as CteName
FROM WSWebCategory as c
WHERE c.ParentIDNo IS NULL
UNION ALL
SELECT
t.ParentIDNo,
t.Category,
t.ChildCategory,
t.WSWebProductNameIDNo,
t.IDNo,
cte.Level + 1 AS Level,
CAST(cte.CteName + '/' + t.ChildCategory AS VARCHAR(1000)) AS CteName
FROM WSWebCategory t
INNER JOIN cte ON t.ParentIDNo = cte.IDNo
)
SELECT *, REPLICATE('----', Level) + CteName as CteName FROM cte
ORDER BY cte.CteName
这给了我一个类似的列表:
/仪器 ----/仪器/高压灭菌器 --------/仪器/高压灭菌器/ALL-AMERICAN 便携式灭菌器 (WAFCO) --------/仪器/高压灭菌器/高压灭菌器配件 ------------/Apparatus/Autoclaves/Autoclave Accessories/Clavies® Autoclave Gloves (Bel-Art Scienceware) ------------/仪器/高压灭菌器/高压灭菌器配件/Grabbit™ Temp Mitts (Heathrow Scientific) ------------/设备/高压灭菌器/高压灭菌器配件/Odo-Clave® 除臭垫(Bel-Art Scienceware) --------/仪器/高压灭菌器/高压灭菌袋 ------------/仪器/高压灭菌器/高压灭菌袋/高压灭菌生物危害处理袋(Bel-Art Scienceware) ------------/仪器/高压灭菌器/高压灭菌袋/高压灭菌生物危害处理袋(Gosselin) ------------/仪器/高压灭菌器/高压灭菌袋/可高压灭菌的高温生物危害处理袋(Bel-Art Scienceware) ------------/仪器/高压灭菌器/高压灭菌袋/Chex-All® II 灭菌袋(本体) ------------/Apparatus/Autoclaves/Autoclave Bags/Clavies® Autoclave Gloves (Bel-Art Scienceware) ------------/Apparatus/Autoclaves/Autoclave Bags/Clavies® Bag Holder (Bel-Art Scienceware) ------------/Apparatus/Autoclaves/Autoclave Bags/Clavies® 通用高压灭菌袋(Bel-Art Scienceware) ------------/Apparatus/Autoclaves/Autoclave Bags/Poxygrid® Biohazard Bag Holder(Bel-Art Scienceware)
但我追求的是一组嵌套的 html 列表:
<ul>
<li>Apparatus
<ul>
<li>Autoclaves
<ul>
<li>ALL-AMERICAN Portable Sterilizers (WAFCO)</li>
<li>Autoclave Accessories
<ul>
<li>Clavies® Autoclave Gloves (Bel-Art Scienceware)</li>
<li>Grabbit™ Temp Mitts (Heathrow Scientific)</li>
<li>Odo-Clave® Deodorant Pads (Bel-Art Scienceware) </li>
</ul>
</li>
<li>Autoclave Bags
<ul>
<li>Autoclavable Biohazard Disposal Bags (Bel-Art Scienceware)</li>
<li>Autoclavable Biohazard Disposal Bags (Gosselin)</li>
<li>Autoclavable Hi-Temp Biohazard Disposal Bags (Bel-Art Scienceware)</li>
<li>Chex-All® II Sterilization Pouches (Propper)</li>
<li>Clavies® Autoclave Gloves (Bel-Art Scienceware)</li>
<li>Clavies® Bag Holder (Bel-Art Scienceware)</li>
<li>Clavies® General Purpose Autoclavable Bags (Bel-Art Scienceware)</li>
<li>Poxygrid® Biohazard Bag Holder (Bel-Art Scienceware)</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
我很困惑如何做到这一点!