sqlserver递归,sqlserver递归查询层级
sqlserver 递归查询
CREATE TABLE #tb1(stuId INT,stuName VARCHAR(30),teaId INT);
在甘谷等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都网站设计、成都网站建设 网站设计制作按需定制,公司网站建设,企业网站建设,高端网站设计,网络营销推广,外贸网站制作,甘谷网站建设费用合理。
INSERT INTO #tb1 (stuId,stuName,teaId)
VALUES(1,'zhou',0),(2,'kong',0),(3,'hong',2),(4,'zhang',1),(5,'liu',4),
(6,'zhao',5),(7,'zheng',6),(8,'wei',7)
;WITH cte AS (
SELECT t.stuId,t.stuName,t.teaId FROM #tb1 AS t
WHERE t.stuId=8
UNION ALL
SELECT t.stuId,t.stuName,t.teaId FROM cte AS c
JOIN #tb1 AS t ON c.teaId=t.stuId
)
SELECT * FROM cte
sqlserver递归算法
With T
As
(
Select * From TB Where newNo=103
Union All
Select TB.* From TB Inner Join T on TB.newNo=T.oldNo
)
Select * From T
怎么用sqlserver实现递归删除目录结构
WITH DirectReports(ManagerID, EmployeeID, Title, EmployeeLevel) AS ( SELECT ManagerID, EmployeeID, Title, 0 AS EmployeeLevel FROM dbo.MyEmployees WHERE ManagerID IS NULL UNION ALL --主要是在此,增加一个union all SELECT e.ManagerID, e.EmployeeID, e.Title, EmployeeLevel + 1 FROM dbo.MyEmployees AS e INNER JOIN DirectReports AS d -- 在此调用自身,就可以实现递归了 ON e.ManagerID = d.EmployeeID ) SELECT ManagerID, EmployeeID, Title, EmployeeLevel FROM DirectReports ORDER BY ManagerID;
sqlserver函数中引用递归
set @p_b = (select fid from w_Storage_Depository where fid in(select fid from dbo.jt_base_company where bj=1))
改成
select @p_b =fid from w_Storage_Depository where fid in(select fid from dbo.jt_base_company where bj=1)
网页名称:sqlserver递归,sqlserver递归查询层级
文章地址:http://cdiso.cn/article/hcseio.html