K
Size: a a a
K
K
OM
K
K
MC
Types don't match between the anchor and the recursive part in column result:with prepare as (
select '+7(041)-875-23-98' as mobilephone, '' as result, 1 as num
union all
select
SUBSTRING(p.MOBILEPHONE, 2, len(p.MOBILEPHONE))
, cast ( result + case when SUBSTRING(p.MOBILEPHONE, 1, 1) like '[0-9]' then SUBSTRING(p.MOBILEPHONE, 1, 1) else '' end as varchar(20))
, num + 1
from prepare as p
where p.MOBILEPHONE > ''
)
select mobilephone, result, num
from prepare
'' as result явно делаешь каст в varchar(20), всё отрабатывает.with prepare as (
select '+7(921)-345-23-58' as mobilephone, cast ('' as varchar(20)) as result, 1 as num
union all
select
SUBSTRING(p.MOBILEPHONE, 2, len(p.MOBILEPHONE))
, cast ( result + case when SUBSTRING(p.MOBILEPHONE, 1, 1) like '[0-9]' then SUBSTRING(p.MOBILEPHONE, 1, 1) else '' end as varchar(20))
, num + 1
from prepare as p
where p.MOBILEPHONE > ''
)
select mobilephone, result, num
from prepare
substring возвращает varchar, когда получает на вход varcharresult что в базовой части CTE, что в рекурсивной)TS
Types don't match between the anchor and the recursive part in column result:with prepare as (
select '+7(041)-875-23-98' as mobilephone, '' as result, 1 as num
union all
select
SUBSTRING(p.MOBILEPHONE, 2, len(p.MOBILEPHONE))
, cast ( result + case when SUBSTRING(p.MOBILEPHONE, 1, 1) like '[0-9]' then SUBSTRING(p.MOBILEPHONE, 1, 1) else '' end as varchar(20))
, num + 1
from prepare as p
where p.MOBILEPHONE > ''
)
select mobilephone, result, num
from prepare
'' as result явно делаешь каст в varchar(20), всё отрабатывает.with prepare as (
select '+7(921)-345-23-58' as mobilephone, cast ('' as varchar(20)) as result, 1 as num
union all
select
SUBSTRING(p.MOBILEPHONE, 2, len(p.MOBILEPHONE))
, cast ( result + case when SUBSTRING(p.MOBILEPHONE, 1, 1) like '[0-9]' then SUBSTRING(p.MOBILEPHONE, 1, 1) else '' end as varchar(20))
, num + 1
from prepare as p
where p.MOBILEPHONE > ''
)
select mobilephone, result, num
from prepare
substring возвращает varchar, когда получает на вход varcharresult что в базовой части CTE, что в рекурсивной)TS
MC
OM

IS
L
AS
К
NP
К
L
L