我有一个菜单结构的网站上工作,所以它可以读取多个见下表子菜单是菜单示例例子
我有几个表像pg_Pages,art_Article,art_Categories,杂志每个表都有一个FK PAGEID在pg_Pages台PK。
我想创建一个SQL查询,将读出这些表中的数据,并创建一个层级菜单结构与每个链接指向正确的网页。
我可能需要经过几个查询字符串的HREF等部分PageID, LanguageID, IssueID and CategoryID
示例链接
Home = Default.aspx?LanguageId=1&IssueID=101&PageID=1
About Us = Page.aspx?LanguageId=1&IssueID=101&PageID=2
Categories = Article-Category.aspx?LanguageId=1&IssueID=101&PageID=6
--Politics = Article-Category.aspx?LanguageId=1&IssueID=101&PageID=6&CategoryID=1
--Economy= Article-Category.aspx?LanguageId=1&IssueID=101&PageID=6&CategoryID=2
--Business= Article-Category.aspx?LanguageId=1&IssueID=101&PageID=6&CategoryID=16
Multimedia = Multimedia.aspx?LanguageId=1&IssueID=101&PageID=10
--Video= Video.aspx?LanguageId=1&IssueID=101&PageID=11
我不知道如何以最佳的方式,没有闪失处理这个问题,因为我已经通过不同的查询字符串,以不同的菜单我感到有点困惑如何处理这种做法,我应该创建一个联盟多个SQL查询来处理这个或不同的东西。 我需要这样一个asp.net网站
我还添加样品的SQL查询,和输出从每个表
SQL
SELECT PageId AS ParentID,SUBSTRING(PageName,0,20) AS PARENT_MENU,SUBSTRING(PageInternalLinkURL,0,24) AS PageHandler, PageLinkPosition,SUBSTRING(PageLayoutPosition,0,14) AS MENU_Type,PageLangID,PageInheritance FROM pg_Pages
SELECT p.PageID as ParentID, SUBSTRING(c.ArticleCategoryName,0,20) AS CHILD_MENU,SUBSTRING(p.PageInternalLinkURL,0,24) AS PageHandler, ArticlePostion,ArticleID AS CHILDID,c.ArticleCategoryID,IssueID,LanguageID FROM art_Articles a JOIN art_Category c ON a.ArticleCategoryID = c.ArticleCategoryID
JOIN pg_pages p ON p.PageID = a.PageID
SELECT p.PageID AS ParentID, IssueCode as CHILD_MENU,SUBSTRING(p.PageInternalLinkURL,0,24) AS PageHandler, m.IssueCode,IssueID AS CHILDID,CurrentIssue,IssueDate,LangID FROM Magazine m JOIN pg_pages p ON m.PageID = p.PageID
SELECT p.PageID AS ParentID, SUBSTRING(c.ArticleCategoryName,0,20) AS CHILD_MENU,SUBSTRING(p.PageInternalLinkURL,0,24) AS PageHandler, LangID,ArticleCategoryID AS CHILDID FROM art_Category c JOIN pg_Pages p ON c.PageID = p.PageID
OUTPUT
ParentID PARENT_MENU PageHandler PageLinkPosition MENU_Type PageLangID PageInheritance
----------- -------------------- ------------------------ ---------------- -------------- ----------- ---------------
1 Home Default.aspx 10 TopMenu 1 0
2 About Us Page.aspx 20 TopMenu 1 0
3 News News.aspx 30 TopMenu 1 0
4 Publication Publication.aspx 40 TopMenu 1 0
5 Articles Articles.aspx 20 TopMenu 1 0
6 Categories Article-Category.aspx 25 TopMenu 1 0
10 Multimedia Multimedia.aspx 60 TopMenu 1 0
11 Video Videos.aspx 10 SubMenu 1 10
12 Archive Default.aspx 40 TopMenu 1 0
ParentID CHILD_MENU PageHandler ArticlePostion CHILDID ArticleCategoryID IssueID LanguageID
----------- -------------------- ------------------------ -------------- ----------- ----------------- ----------- -----------
5 Politics Articles.aspx 10 12 1 1 1
5 Politics Articles.aspx 10 13 1 3 1
5 Politics Articles.aspx 10 14 1 4 1
5 Politics Articles.aspx 1 15 1 5 1
5 Politics Articles.aspx 20 16 1 5 1
5 Business Articles.aspx 30 17 16 5 1
5 Group News Articles.aspx 40 18 6 5 1
5 Infrastructure Articles.aspx 50 23 17 5 1
5 Group News Articles.aspx 60 24 6 5 1
5 Book Review Articles.aspx 70 25 18 5 1
ParentID CHILD_MENU PageHandler IssueCode CHILDID CurrentIssue IssueDate LangID
----------- ----------- ------------------------ ----------- ----------- ------------ ----------------------- -----------
12 106 Default.aspx 106 1 0 2012-09-01 00:00:00.000 1
12 106 Default.aspx 106 2 1 2012-09-01 00:00:00.000 2
12 102 Default.aspx 102 3 1 2011-11-01 00:00:00.000 1
12 103 Default.aspx 103 4 1 2012-02-01 00:00:00.000 1
12 109 Default.aspx 109 5 1 2012-12-01 00:00:00.000 1
ParentID CHILD_MENU PageHandler LangID CHILDID
----------- -------------------- ------------------------ ----------- -----------
6 Politics Article-Category.aspx 1 1
6 Economy Article-Category.aspx 1 2
6 Culture Article-Category.aspx 1 3
6 Sports Article-Category.aspx 1 4
6 xxxxxxxxxxxxxxxxxxx Article-Category.aspx 1 5
6 Group News Article-Category.aspx 1 6
6 People Article-Category.aspx 1 7
6 Editorial Message Article-Category.aspx 1 8
6 Chairman's Message Article-Category.aspx 1 9
6 Business Article-Category.aspx 1 16
6 Infrastructure Article-Category.aspx 1 17
6 Book Review Article-Category.aspx 1 18
6 Finance Article-Category.aspx 1 19
6 Lifestyle Article-Category.aspx 1 20
6 Others Article-Category.aspx NULL 21