递归查询在ColdFusion 9中不起作用

时间:2015-02-23 16:23:44

标签: sql-server-2008 coldfusion coldfusion-9 common-table-expression

在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'

两者都不返回

0 个答案:

没有答案