日期:2014-05-18  浏览次数:20773 次

谁能帮我看一下这个视图,为什么只能查出根节点的内容啊?
ALTER VIEW [dbo].[V_SAP_OITTTREE]
AS
WITH BOM(PreGrpid, PreGrpName, Grpid, GrpName,LEVEL, iconCls) 
AS 
(SELECT S1.PreGrpid, S2.GrpName, S1.Grpid,S1.GrpName, 1 AS bomlevel, 'icon-tree-root'
  FROM V_SAP_ITT1 S1 LEFT JOIN
  V_SAP_ITT1 S2 ON S1.PreGrpid = S2.Grpid
  WHERE S1.Grpid = '-1'
  UNION ALL
  SELECT S1.PreGrpid, B.GrpName, S1.Grpid, S1.GrpName,B. LEVEL + 1, 
  'icon-item-grps'
  FROM V_SAP_ITT1 S1 INNER JOIN
  BOM B ON S1.PreGrpid = B.Grpid
  WHERE S1.Grpid <> '-1')
SELECT PreGrpid, PreGrpName, Grpid,GrpName, Level, iconCls
 FROM (SELECT ROW_NUMBER() OVER (ORDER BY LEVEL, PreGrpName, GrpName) [id], PreGrpid, PreGrpName, Grpid,GrpName,
  Level, iconCls
 FROM BOM B
 WHERE B.Grpid <= 0
UNION ALL
SELECT ROW_NUMBER() OVER (ORDER BY LEVEL, PreGrpName, GrpName) [id], PreGrpid, PreGrpName, Grpid,GrpName,Level, iconCls
FROM BOM B
WHERE B.Grpid > 0
) A
 
这个是查询多级菜单,其中PreGrpid, PreGrpName, Grpid, GrpName在表中都是字符型的,请帮我看一下怎么改

------解决方案--------------------
你要做什么,把数据贴出来,好不好。
------解决方案--------------------
这样比较难理解LZ的意思,贴出表结构、数据、执行后的结果及想要达到的目的