SQL递归查询部门
create function [dbo].[DeptTree](@initDeptCode varchar(10))/*定义函数c_tree,输入参数为初始节点DeptCode*/
returns @t table(DeptCode varchar(10),UpDeptCode varchar(10),lev int)/*定义表t用来存放取出的数据*/
begin
declare @i int/*标志递归级别*/
set @i=1
insert @t select DeptCode,UpDeptCode,@i from vi_dept where DeptCode=@initDeptCode
while @@rowcount<>0
begin
set @i=@i+1
insert @t select a.DeptCode,a.UpDeptCode,@i from vi_dept as a,@t as b
where b.DeptCode=a.UpDeptCode and b.lev=@i-1
end
return
end
select * from dbo.DeptTree('0000')
相关文档:
行列转换
create table test(id int,name varchar(20),quarter int,profile int)
insert into test values(1,'a',1,1000)
insert into test values(1,'a',2,2000)
insert into test values(1,'a',3,4000)
insert into test values(1,'a',4,5000)
insert into test values(2,'b',1,3000)
insert into test values(2, ......
有关分页 SQL 的资料很多,有的使用存储过程,有的使用游标。本人不喜欢使用游标,我觉得它耗资、效率低;使用存储过程是个不错的选择,因为存储过程是经过预编译的,执行效率高,也更灵活。先看看单条 SQL 语句的分页 SQL 吧。
方法1:
适用于 SQL Server 2000/2005
SELECT TOP 页大小 *
from tab ......
sql权限:
创建User:
insert into mysql.user(Host,User,Password)
values("localhost","cordev",password("xasoftorg"));
insert into
mysql.user(Host,User,Password)
values("localhost","corhotfix",password("xasoftorg"));
insert into
mysq ......
在写sql语句时,一般都是一句解决,从来没想过说,把sql语句拆开来写。
例如下面这句: string readstring = "select * from 实例 where 实例ID='"+eid+"'";
然后执行 Myconnection();
DataSet ds = new DataSet();
OleD ......