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

[转]生成无级树(sql函数)

--处理示例
--示例数据
create table tb(ID int,Name varchar(10),ParentID int)
insert tb select 1,'AAAA'    ,0
union all select 2,'BBBB'    ,0
union all select 3,'CCCC'    ,0
union all select 4,'AAAA-1'  ,1
union all select 5,'AAAA-2'  ,1
union all select 6,'BBBB-1'  ,2
union all select 7,'CCCC-1'  ,3
union all select 8,'CCCC-2'  ,3
union all select 9,'AAAA-1-1',4
go
--创建处理的函数
create function f_id()
returns @re table(id int,level int,sid varchar(8000))
as
begin
    declare @l int
    set @l=0
    insert @re select id,@l,right(10000+id,4)
    from tb where ParentID=0
    while @@rowcount>0
    begin
        set @l=@l+1
        insert @re select a.id,@l,b.sid+','+right(10000+a.id,4)
        from tb a,@re b
        where a.ParentID=b.id and b.level=@l-1
    end
    return
end
go
--调用函数实现查询
select a.*,带缩进的Name=space(b.level*4)+a.Name
from tb a,f_id() b
where a.id=b.id
order by b.sid
go
--删除测试
drop table tb
drop function f_
[转]http://www.cnblogs.com/catxp/articles/381747.html


相关文档:

SQL Server性能优化的一些技巧


数据库性能优化涉及到很多方面,在数据库开发时可以通过一些基本的优化技巧提高数据库的性能:
1.原则上为创建的每个表都建立一个主键,主键唯一标识某一行记录,用于强制表的实体完整性。SQL Server 2005 Database Engine 将通过为主键列创建唯一索引来强制数据的唯一性。查询中使用主键时,此索引还可用来对数据进行快 ......

从【各大软件公司笔试压轴题】学习SQL语句

从博客园中看到一篇文章,介绍大软件公司面试时常常会出的两道SQL题(见附录)。
我觉得受益很多,在此之前,我一直觉得,SQL2008似乎提供了这方面的支持,但更低的版本,包括2005,非游标做不出来(水平够菜)。总结心得如下:
1、    强大的group by
1
 select stdname,
2
 isnull(s ......

MyEclipse5.5下连接Sql Server 2008的方法

下面是指导文档。请跟着一步步的做。就能成功连接上sql server 2008
 
java中连接sql server 2008的注意事项:
2000,2005的数据库驱动类的写法是:
com.microsoft.jdbc.sqlserver.SQLServerDriver
URL的写法是:假设数据库是news
jdbc:microsoft:sqlserver://localhost:1433;databaseName=news
 
但是20 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号