sql server - String concatenation issue in CTE SQL -
i have following cte sql
with tasks ( select taskid, parenttaskid, cast(sortkey nchar) sort_key /*,cast(sortkey char) sort_key */ oatasks s (taskid = 1) union select s2.taskid, s2.parenttaskid ,cast( '0.'+ cast(tasks_2.sort_key nchar) + '0.' + cast(s2.sortkey nchar) nchar) sort_key /*,cast(tasks_2.sort_key +'.'+ cast(s2.sortkey char) char)*/ oatasks s2 inner join tasks tasks_2 on tasks_2.taskid = s2.parenttaskid ) select tasks_1.taskid, oatasks.task, oatasks.parenttaskid , oatasks.sortkey,tasks_1.sort_key tasks tasks_1 inner join oatasks on tasks_1.taskid = oatasks.taskid
in sort_key column not getting desired format should 01, 01.01, 01.01.01 etc.
i'm getting 1, 0.1, 0.1.1
. suggestion?
try right select right('00',1,2) gives 01
Comments
Post a Comment