我在执行我的sql查询时遇到错误"类型不在锚和递归之间匹配"。 我的问题:
;WITH FA_CTE AS
(
SELECT
fa.name as Data1,
fa.lnumber as Data2,
fa.allnumber as Data3,
fa.productname as Data4
FROM
(
SELECT A.name, A.lnumber, A.allnumber, A.productname
FROM soldproduct AS A INNER JOIN Account AS B ON A.account = B.accountid
) fa
)
, tmp1(Data1, Data2, Data3, DataItem , Data4) as (
select Data1, Data2, Data3, LEFT(Data4, CHARINDEX('-',Data4+'-')-1),
STUFF(Data4, 1, CHARINDEX('-',Data4+'-'), '')
from FA_CTE
union all
select Data1, Data2, Data3, LEFT(Data4, CHARINDEX('-',Data4+'-')-1),
STUFF(Data4, 1, CHARINDEX('-',Data4+'-'), '')
from tmp1
)
select Data1, Data2, Data3, DataItem AS Data4
from tmp1
order by Data1
答案 0 :(得分:1)
不要问我为什么SQL Server在使用递归CTE时遇到字符串长度问题,但我过去通过显式地转换计算字符串列来解决这个问题:
price