Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Shifting the rows

Author  Topic 

ayamas
Aged Yak Warrior

552 Posts

Posted - 2009-04-16 : 09:49:49
Hi Guys,

Hi have a resultset like this.
[url]http://img9.imageshack.us/img9/489/imgydu.jpg[/url]

I want to shif the row containing #of Claims one row above & the row containing SUM in column iClaimId in place of it.

Is it possible?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-16 : 10:57:11
Most likely to be done in presentation layer

Is this?


declare @t table(id int identity(1,1),cnt varchar(100), claimid varchar(100))
insert into @t(cnt,claimid)
select '','345' union all
select '','SUM' union all
select '# of claims','' union all
select '','7345' union all
select '','6834' union all
select '','SUM' union all
select '# of claims',''

select * from @t
select t1.id,case when t1.cnt='' then coalesce(t2.cnt,'') else '' end,t1.claimid from @t as t1 left join
(
select t1.id,t2.cnt as cnt from @t as t1 inner join
(
select * from @t
where cnt like '#%'
) as t2
on t1.id+1=t2.id
where t1.claimid like 'sum%'
) as t2
on t1.id=t2.id


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-04-16 : 11:12:02
yup. its possible. if excel just right click on row and select insert row above. then copy and paste values to top and copy the other row to current row position.
If in sql report add a row above and copy the expressions from current row to top and from bottom one to current and delete the bottom row
Go to Top of Page
   

- Advertisement -