create table #test (id int) insert into #test(id) select 10 union all select 20 union all select 30 union all select 40 union all select 50 declare @Ids varchar(100) select @Ids=coalesce(@Ids+'~','')+cast(T.id as varchar(10)) from (select top 2 id from #test order by id desc)T select @Ids 'RequiredData' drop table #test
select STUFF((SELECT '-' + numbers AS [text()] FROM ( select top 2* from ( select * from [TableName] EXCEPT select top (select (COUNT(1)-2) from [TableName]) * from [TableName])A )B FOR XML PATH('') ), 1, 1, '' )MergedCells
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)