首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

列的“HW_PART_NO”递归查询“CTE”锚和递归部分之间的类型不匹配。解决方案

2012-03-27 
列的“HW_PART_NO”递归查询“CTE”锚和递归部分之间的类型不匹配。求解决SQL codewith cte as(select [SRV_PA

列的“HW_PART_NO”递归查询“CTE”锚和递归部分之间的类型不匹配。
求解决


SQL code
;with cte as(select [SRV_PART_NO],[HW_PART_NO]=substring(case when right([HW_PART_NO],1)=';' then [HW_PART_NO] else [HW_PART_NO]+';' end,1,charindex(';',case when right([HW_PART_NO],1)=';' then [HW_PART_NO] else [HW_PART_NO]+';' end)-1),col3=stuff(case when right([HW_PART_NO],1)=';' then [HW_PART_NO] else [HW_PART_NO]+';' end,1,charindex(';',case when right([HW_PART_NO],1)=';' then [HW_PART_NO] else [HW_PART_NO]+';' end),'') from win7_32union allselect [SRV_PART_NO],[HW_PART_NO]=substring(col3,1,charindex(';',col3)-1),col3=stuff(col3,1,charindex(';',col3),'') from ctewhere charindex(';',col3)>0)--insert into [Commdity Split] ([HW Part No],[HW_PART_NO])select distinct [SRV_PART_NO],[HW_PART_NO]  from cte




报错


Types don't match between the anchor and the recursive part in column "HW_PART_NO" of recursive query "cte".


[解决办法]
try:

SQL code
;with cte as(select [SRV_PART_NO],[HW_PART_NO]=cast(substring(case when right([HW_PART_NO],1)=';' then [HW_PART_NO] else [HW_PART_NO]+';' end,1,charindex(';',case when right([HW_PART_NO],1)=';' then [HW_PART_NO] else [HW_PART_NO]+';' end)-1) as varchar(2000)),col3=cast(stuff(case when right([HW_PART_NO],1)=';' then [HW_PART_NO] else [HW_PART_NO]+';' end,1,charindex(';',case when right([HW_PART_NO],1)=';' then [HW_PART_NO] else [HW_PART_NO]+';' end),'') as varchar(2000)) from win7_32union allselect [SRV_PART_NO],[HW_PART_NO]=cast(substring(col3,1,charindex(';',col3)-1),col3=stuff(col3,1,charindex(';',col3),'') as varchar(2000)) from ctewhere charindex(';',col3)>0)--insert into [Commdity Split] ([HW Part No],[HW_PART_NO])select distinct [SRV_PART_NO],[HW_PART_NO]  from cte
[解决办法]
探讨
ok.谢谢.我想请问一下,加上cast为它设置一个类型大小有和作用?
我本来前面的拆分字段也是如上所写,但是没有加上cast,可以运行

热点排行