ptype_parentId有没有索引?
解决方案 »
- 关于利用分布式分区视图实现联合数据库服务器的问题?
- 麻烦大家帮忙看一下我的自定义函数,问题出在哪里?
- 又来了,一个简单的语句,莫笑我,今天蒙了
- 求一个SQL语句能实现如下查询,高手来解题!!!
- 求教,SQL Server中如何返回指定的第n到m行的记录?或查询时自动添加行号?
- 紧急求助几个问题
- 在存儲過程中有什麼方法取得記錄的記錄號?
- $$$特急!SQL Server访问出错$$$
- 存储过程中返回的RECORDSET不支持BOOKMARK??!
- 怎样在存储过程中使用另一个存储过程返回的数据集?
- 在A字段相同的前提下把B字段内的字符串连接起来,用一个SQL语句写出来。
- 如何加密存储过程、触发器?
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 (' ',(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
如果是在在程序里测的,用CCEO的方法试试。