Q&A for professional and enthusiast programmers
declare cur_db cursor for select * from string_split(db_name(),'.') order by row_number() over( order by (select 1)) desc declare @revname nvarchar(128) declare @part nvarchar(128) SELECT concat( 'http://' , case PARSENAME(db_name(),1) when 'audio' then 'avp' else PARSENAME(db_name(),1) end , '.' + case PARSENAME(db_name(),2) when 'audio' then 'avp' else PARSENAME(db_name(),2) end , IIF(patindex('%.MathOverflow%',db_name()) > 0 , '' , '.' + PARSENAME(db_name(),3) ) , IIF(patindex('%.MathOverflow%',db_name()) > 0 , '.net' , '.com' ) ) , db_name() select value + '.' as [text()] -- coalesce(@revname + '.','') + rtrim(value) from string_split(db_name(),'.') where value is not null order by row_number() over( order by (select 1)) desc for xml path('') select @revname = coalesce(@revname +'.','') + value from string_split(db_name(),'.') order by row_number() over( order by (select 1)) desc select '1: ' + @revname select @revname = coalesce(@revname +'.','') + nmp from ( select case value when 'audio' then 'Avp' else value end as nmp ,row_number() over( order by (select 1)) as rn from string_split(db_name(),'.') ) as reversed order by rn desc -- order by row_number() over( order by (select 1)) desc /* open cur_db; fetch next from cur_db into @part while(@@FETCH_STATUS = 0) begin set @revname = @revname + case @part when 'Audio' then 'Avp' else @part end fetch next from cur_db into @part if (@@FETCH_STATUS = 0) set @revname = @revname + '.' end close cur_db; */ select value from string_split(db_name(),'.') order by row_number() over( order by (select 1)) desc select @revname; /* select @revname = coalesce(@revname +', ','') + title from posts where id > 1460 and title is not null select @revname;*/