易截截图软件、单文件、免安装、纯绿色、仅160KB

SQL树节点排序 - MS-SQL Server / 应用实例

数据如下
InvCategoryID CategoryName CreateTime ParentID Path ItemType CategoryType ShowIndex 
1 Consumables 2010-04-14 0 1 0 1 2
2 Equipments 2010-04-14 0 2 2 1 1
3 Miscellaneous 2010-04-14 0 3 1 1 4
4 Other 2010-04-14 17:14:28.310 0 4 2 2 3
5 Paper 2010-04-14 18:20:34.607 1 1,5 1 1 0
6 Other 2010-04-14 18:29:53.187 1 1,6 1 1 7
7 Tabulation 2010-04-15 2 2,7 2 1 0
8 Parts 2010-04-20 15:01:05.997 2 2,8 2 1 0
9 Computer 2010-04-20 15:01:24.890 2 2,9 2 1 0
10 Other 2010-04-20 15:02:09.733 2 2,10 2 1 3

要求查询结果按照Path产生树结构,并同时节点按照ShowIndex排序(树结构优先,同级节点按照ShowIndex排序)
例如
CategoryName Path ShowIndex 
Equipments 2 1
Tabulation 2,7 0
Other 2,10 3
Consumables 1 2



附表数据SQL
if exists (select * from sysobjects where id = OBJECT_ID('[EMS_InventoryCategory]') and OBJECTPROPERTY(id, 'IsUserTable') = 1) 
DROP TABLE [EMS_InventoryCategory]

CREATE TABLE [EMS_InventoryCategory] (
[InvCategoryID] [int] IDENTITY (1, 1) NOT NULL,
[CategoryName] [varchar] (30) NULL,
[CreateTime] [datetime] NULL DEFAULT (getdate()),
[ParentID] [int] NOT NULL DEFAULT ((0)),
[Path] [varchar] (1000) NULL,
[ItemType] [tinyint] NULL DEFAULT ((0)),
[CategoryType] [tinyint] NULL DEFAULT ((0)),
[ShowIndex] [int] NOT NULL DEFAULT


相关问答:

jsp链接sql2000的疑问?



type Exception report


message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jas ......

求一sql语句 - MS-SQL Server / 疑难问题

现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......

MS SQL作业问题 - MS-SQL Server / 应用实例

如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP

参考:http://hi.baidu.com/toiota ......

一条 SQL - Oracle / 基础和管理

有这样一条SQL
 Select Get_Costtaxrate(col1), Get_Tcostvalue(col1) from a
 
其中Get_Costtaxrate、Get_Tcostvalue都是函数,这两个函数里面都是查找一个大表,Get_Tcostvalue还需要调用Get_C ......

求一条SQL语句 - MS-SQL Server / 应用实例

原SQL语句SQL code:

SELECT t6.FName '操作工',t1.FDate '日期',t5.FName '制单人',t3.FName '设备',t4.FName '班制',
t7.FBillNo '工艺指令单号',t8.FName '岗位',t2. ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号