Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have data like
10
20
30
40
50

I want data like 40~50 (that means last two rows merge data)
Posted
Comments
Basmeh Awad 4-Feb-14 10:18am    
is the value permanent like 40 and 50 or any data in the last two rows????
Sandeep Kumar Sinha 4-Feb-14 22:55pm    
Hi Basmeh.. there are any data in last two rows.. not mandatorily 40 50.. i give this as example.. please suggest the solution if you have any ..
Thanks,
Sandeep
Andrius Leonavicius 4-Feb-14 16:51pm    
Hi,

Could you please give us more information about data merging?

try this
SQL
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
 
Share this answer
 
Hi,

Try this query....
SQL
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

Regards,
GVPrabu
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900