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
相关问答:
执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
从数据库中查询一张表的数据
select 部门,姓名 from tb
如何才能生成下面的xml格式
XML code:
<folder state="unchecked" label="全部">
<folder state="unchecked&qu ......
字段1,字段2.....字段N,Status,ParentID
1,Name1....test1,1,99
1,Name1....test1,3,99
1,Name2....test2,1,101
1,Name2....test2,3,101
1,Name3....test3,2,101
1,Name1....test1,4,101
想要的结果是:
1,Na ......
将一个查询语句赋给一个变量,如下:
DECLARE @STR NVARCHAR(MAX)
SET @STR='SELECT * from SALE_PROD'
怎么样才能执行它呢?
请高手,仁兄,侠姐帮帮忙啊
多谢,可以啦,高手啊
直接执行就行了
exec ......