在SQL Server 2008中运行时,此查询返回一堆结果
WITH c
AS
(
SELECT deptid, reports_to_dept
FROM glo_tree
WHERE deptid = '#deptid#'
UNION ALL
SELECT t.deptid, t.reports_to_dept
FROM glo_tree T
INNER JOIN c
ON t.deptid = c.reports_to_dept
)
SELECT deptid
FROM c
然而,在Cold Fusion 9中运行时,返回0条记录(无任何错误)
有趣的是,我创建了一个运行查询的SQL函数,然后是一个执行该函数的存储过程,其中一个也返回空白!
CREATE FUNCTION [dbo].[checkDept] (@deptid varchar(16))
RETURNS TABLE
AS
RETURN
(
WITH c
AS
(
SELECT deptid, reports_to_dept
FROM glo_tree
WHERE deptid = @deptid
UNION ALL
SELECT t.deptid, t.reports_to_dept
FROM glo_tree T
INNER JOIN c
ON t.deptid = c.reports_to_dept
)
SELECT deptid
FROM c
)
GO
CREATE PROCEDURE [dbo].[getDept] (@deptid varchar(16))
AS
SELECT deptid
FROM dbo.checkDept(@deptid)
然后像
一样打电话给他们select * FROM checkDept('18538')
exec getDept @deptid='18538'
两者都不返回