ptype_parentId有没有索引?

解决方案 »

  1.   

    试试:CREATE PROCEDURE dbo.jy_get_ptype AS
    SET NOCOUNT ON 
    declare @temp table(ptype_Id  int,ordertype varchar(20)) insert @temp 
    select ptype_Id,cast(ptype_Id as varchar(20)) 
    from ptype_mstr where ptype_parentId =0 while exists ( 
    select a.ptype_Id,t.ordertype+cast(a.ptype_Id as varchar(20)) 
    from ptype_mstr a,@Temp t 
    where a.ptype_parentId <>0 
    and a.ptype_parentId=t.ptype_Id and not exists ( 
    select * from @temp 
    where ptype_id=a.ptype_Id 
    ) ) 
    insert @temp 
    select a.ptype_id,t.ordertype+cast(a.ptype_Id as varchar(20)) 
    from ptype_mstr a,@Temp t 
    where a.ptype_parentId <>0 
    and a.ptype_parentId=t.ptype_id 
    and not exists ( 
    select * from @temp 
    where ptype_Id=a.ptype_Id 

    select REPLICATE (' &nbsp;',(a.ptype_level-1)*2) +ptype_desc as ptype_desc,a.ptype_desc as edit_ptype_desc,cast(a.ptype_level as varchar(20))+'级类别' as ptype_level,a.ptype_part,a.ptype_rmks,a.ptype_id
    from ptype_mstr a,@Temp t 
    where a.ptype_Id=t.ptype_Id 
    order by ordertype
    GO
      

  2.   

    367笔,应该不到一秒的,你是不是在程序里测的?在查询分析器查询试试!
    如果是在在程序里测的,用CCEO的方法试试。