【发布时间】:2019-09-27 08:20:33
【问题描述】:
我有一个如下的 CTE,它实际上是从 VSTS 数据中找到所有工作项及其父项。
;with cte(wtype,id,parent,title,ptype,WILevel,ParentTitle) as
(
select WorkItemType,wi_id,parent,title,ParentType,0 as WILevel,'' as ParentTitle from tbl_VSTS_AllWorkItems where Parent is null and state<>'Removed'
union all
select WorkItemType,wi_id,W.parent,W.title,ParentType=t2.wtype,(t2.WILevel+1) as WILevel, t2.title as ParentTitle from tbl_VSTS_AllWorkItems W inner join cte t2 on t2.id=W.Parent where state<>'Removed'
)
select * from cte where WILevel=0;
但是我得到如下的转换错误。
消息 240,第 16 级,状态 1,第 8 行 递归查询“cte”的“ParentTitle”列中的锚点和递归部分的类型不匹配。
我不明白这个问题,因为标题字段只是 varchar 类型。那么为什么类型不匹配?
【问题讨论】:
-
tbl_VSTS_AllWorkItems.title的列类型是什么?
标签: sql tsql common-table-expression