我們正在將一個應用程序從oracle遷移到SQL Server。返回Xml和Html的SQL Server查詢
在Oracle中,一個過程用於返回嵌入了一些HTML標記的XML。
來源如下。
SELECT XMLAGG (
XMLFOREST (
XMLELEMENT ("a", XMLATTRIBUTES ('#' AS "href"), MODULENAME) "h3",
XMLELEMENT (
"ul",
XMLAGG (
XMLELEMENT (
"li",
XMLELEMENT (
"a",
XMLATTRIBUTES (
'#' AS "href",
'pageclick('''
|| SCREENPATH
|| ''','|| SCREENID||')' AS "onclick"),
SCREENNAME))
ORDER BY SORDER ASC)) "div")
ORDER BY MORDER ASC).getclobval()
FROM (SELECT B.SUBMODULEID MODULEID,
C.PAGEID SCREENID,
C.PAGENAME SCREENNAME,
C.PAGECODE,
B.SUBMODULEID,
B.SUBMODULENAME MODULENAME,
C.PAGEURLL1 SCREENPATH,
C.ORDERNO SORDER,
B.ORDERNO MORDER
FROM SETP.SM_PAGES C,
SETP.SM_MODULES A,
SETP.SM_SUB_MODULES B,
SETP.SM_USRPRIVHDR D,
SETP.SM_USRPRIVDTL E
WHERE D.USRPRIVID = E.USRPRIVID
AND C.PAGEID = E.PAGEID
AND B.MODULEID = A.MODULEID
AND C.SUBMODULEID = B.SUBMODULEID
AND D.USRID = 2) page
GROUP BY MODULENAME, MORDER;
,這裏是輸出
<h3>
<a href="#">Masters</a>
</h3>
<div>
<ul>
<li>
<a href="#" onclick="pageclick('WmsSetup.aspx/BaggingConfig',1177)">Bagging Configuration</a>
</li>
<li>
<a href="#" onclick="pageclick('WMS.aspx/Items',1171)">Item Master</a>
</li>
</ul>
</div>
我一直在分裂我的頭髮,實現SQL Server中的相同,而無需使用XSLT。 任何想法?
感謝&問候
的SQL Server版本? – JeffO 2012-03-21 12:00:48
SQL Server 2005 Prof/Ent。 – Deb 2012-03-21 12:19:26
現在你有15個聲望點 - 所以你可以** upvote ** Mikael的優秀答案! :-) – 2012-03-21 12:40:45