消息 240,级别 16,状态 1,过程 fenduanqiankuan,第 23 行
在递归查询 "cte" 的列 "qr" 中,定位点类型和递归部分的类型不匹配。
消息 240,级别 16,状态 1,过程 fenduanqiankuan,第 23 行
在递归查询 "cte" 的列 "je" 中,定位点类型和递归部分的类型不匹配。

该错误是当我建立如下存储过程时产生的:
-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters 
-- command (Ctrl-Shift-M) to fill in the parameter 
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
alter PROCEDURE fenduanqiankuan
AS
BEGIN
--create table jkb(cid int,jkje int,jksj datetime)
--insert into jkb select 1,500,'2008-1-1'
--insert into jkb select 2,780,'2008-1-2'
--create table hkb(cid int,hksj datetime,hkje int)
--insert into hkb select 1,'2008-1-3',100
--insert into hkb select 1,'2008-1-5',200
--insert into hkb select 1,'2008-1-7',50
--insert into hkb select 1,'2008-1-11',100
--insert into hkb select 2,'2008-1-8',250
--insert into hkb select 2,'2008-1-11',80
--insert into hkb select 2,'2008-1-15',200
--go
declare @d datetime
set @d='2008-1-30'
;with cte as
(
select '1' head,jjh,jksj as qr,(select isnull(case when min(hksj)>@d then @d else min(hksj) end,@d) from HuanKuanBiao where jjh=a.jjh) as zr,jkje as je,(select max(hksj) from HuanKuanBiao where jjh=a.jjh and hksj<=@d) as jzr from YongHuXinXi a where jksj<@d
union all
select '2' head,super.jjh,super.zr as qr,sub.hksj as zr,super.je-(select hkje from HuanKuanBiao where hksj=super.zr and jjh=super.jjh) as je,super.jzr from cte super inner join HuanKuanBiao sub on super.jjh=sub.jjh
 where sub.hksj>super.zr and not exists(select 1 from HuanKuanBiao where jjh=super.jjh and hksj>super.zr and hksj<sub.hksj) and sub.hksj<=@d
union all
select '3' head,a.jjh,a.zr as qr,@d as zr,a.je-b.hkje as je,a.jzr from cte a inner join HuanKuanBiao b on a.jjh=b.jjh where a.jzr=a.zr and a.jzr=b.hksj and a.jzr<@d
)
select head,jjh,qr,zr,DATEDIFF(day,qr,zr) ts,je from cte order by jjh,qr
--drop table jkb,hkb
END
GO