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)
 compress the values..

Author  Topic 

ganny
Yak Posting Veteran

51 Posts

Posted - 2009-10-14 : 05:29:04
Hi,

I would like to compress the values to show only once in the table. For example the table is like this:

TicketNo SeatNo Amount
============================
AA1 11 100
AA1 12 100
BB2 22 200
BB2 23 200
BB2 25 200
CC3 41 150
CC3 44 150

The expected output of the table should be:

TicketNo SeatNo Amount
============================
AA1 11 100
AA1 12 -
BB2 22 200
BB2 23 -
BB2 25 -
CC3 41 150
CC3 44 -


Kindly assist me.


YellowBug
Aged Yak Warrior

616 Posts

Posted - 2009-10-14 : 08:25:07
This can easily be done in the presentation layer. Most reporting tools have an identical suppress option.
Do you really require this in SQL?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-14 : 08:31:41
quote:
Originally posted by ganny

Hi,

I would like to compress the values to show only once in the table. For example the table is like this:

TicketNo SeatNo Amount
============================
AA1 11 100
AA1 12 100
BB2 22 200
BB2 23 200
BB2 25 200
CC3 41 150
CC3 44 150

The expected output of the table should be:

TicketNo SeatNo Amount
============================
AA1 11 100
AA1 12 -
BB2 22 200
BB2 23 -
BB2 25 -
CC3 41 150
CC3 44 -


Kindly assist me.





Where do you want to show data?

Madhivanan

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

ganny
Yak Posting Veteran

51 Posts

Posted - 2009-10-15 : 01:05:45
Hi, i would like to show in sql since the other application based on this result.

Pls help if any posibilities.
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-10-15 : 01:20:51
Hi Try this once.

SELECT TicketNo,SeatNo,CASE WHEN rid = 1 THEN Amount ELSE NULL END AS 'Amount' FROM
( SELECT *,ROW_NUMBER() OVER( PARTITION BY TicketNo ORDER BY TicketNo ) AS rid FROM @temp) t
Go to Top of Page
   

- Advertisement -