У меня есть следующий CTE SQL
WITH Tasks AS (
SELECT TaskID, ParentTaskID, CAST(SortKey AS nChar) AS sort_key
/*,cast(SortKey as char) as sort_key */
FROM oaTasks AS s
WHERE (TaskID = 1)
UNION ALL
SELECT s2.TaskID, s2.ParentTaskID
,Cast( '0.'+ cast(Tasks_2.sort_key as NCHAR)
+ '0.' + cast(s2.SortKey as NCHAR) as NCHAR) AS sort_key
/*,cast(Tasks_2.sort_key +'.'+ cast(s2.SortKey as char) as char)*/
FROM oaTasks AS s2
INNER JOIN Tasks AS Tasks_2
ON Tasks_2.TaskID = s2.ParentTaskID
)
SELECT Tasks_1.TaskID, oaTasks.Task, oaTasks.ParentTaskID
, oaTasks.SortKey,Tasks_1.sort_key
FROM Tasks AS Tasks_1
INNER JOIN oaTasks ON Tasks_1.TaskID = oaTasks.TaskID
В столбце sort_key я не получаю желаемый формат, который должен быть похож на 01, 01.01, 01.01.01 etc.
, но я получаю 1, 0.1, 0.1.1
. Любое предложение?