2 metu Metu_ 于 2014.12.16 14:14 提问

Oracle转sqlserver语句

关于START WITH...CONNECT BY PRIOR语句转成sqlserver的问题

数据库换成了SQLServer 然后一些sql语句报错了

SELECT ORG_ID FROM pub_organ START WITH ORG_ID='33333' CONNECT BY PRIOR org_ID=PARENT_CODE

sqlserver好像不识别这个词组 求大神帮忙转换成可执行的sqlserver的语句

小弟在此谢过

1个回答

ACMAIN_CHM
ACMAIN_CHM   Ds   Rxr 2014.12.28 22:18

在SQL SERVER中使用CTR,可以百度一下 CTE

ACMAIN_CHM
ACMAIN_CHM WITH DirectReports(ManagerID, EmployeeID, Title, EmployeeLevel) AS ( SELECT ManagerID, EmployeeID, Title, 0 AS EmployeeLevel FROM dbo.MyEmployees WHERE ManagerID IS NULL 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; GO
接近 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片