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.
| Author |
Topic |
|
trickedicky
Starting Member
1 Post |
Posted - 2007-11-19 : 09:49:16
|
| Hi, i have a table, that i am trying to compare values. I want to highlight the cheapest field's contents (price) for each tuple. The field itself could be different for each field depending on its price. the table i have is below;Pos | AlbumTitle | Artist |Virgin | Woolworths | hmv-----+---------------+--------------+-------+-------------+---------1 | Confessions | Usher | 2.99 | 9.99 | 13.792 | Back Home | Westlife | 2.00 | 5.99 | 3.193 | Spirit | Leona | 5.99 | 2.99 | 13.994 | Trust Me |Craig David| 7.99 | 11.99 | 6.635 | Sawdust | Killers | 22.99 | 10.99 | 8.396 | Greatest Hits |Spice Girls| 12.99 | 0.99 | 13.79im not sure if this would be a good format for the table, i cant figure out how to find out which field is the lowest value and how at all i would be able to make the value itself bold or stand out somehow.Any help/advice would be welcome!!!Rich |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-11-19 : 09:53:01
|
| This is not something that you do in SQL, you do it on your report or webpage or wherever you are displaying the data. there is now way to make a column "bold" in SQL Server, it is a database, not a presentation tool.- Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
|
Hommer
Aged Yak Warrior
808 Posts |
Posted - 2007-11-19 : 10:01:16
|
| To make it bold is a presentation issue, which does not belong to here.Use min() function to return the lowest value in a given column. When you said "for each tuple", did you mean to identify the 2.99 value for Pos 1? |
 |
|
|
jhocutt
Constraint Violating Yak Guru
385 Posts |
Posted - 2007-11-19 : 10:16:37
|
| No it is not a good format.Price data should be in a seperate table. That being said here is a way to get the lowest price per tuple.declare @A table (pos int, AlbumTitle varchar(100), Artist varchar(100), Virgin float, Woolworths float, hmv float)insert into @A select 1 , 'Confessions' , 'Usher' , 2.99 , 9.99 , 13.79union allselect 2 , 'Back Home' , 'Westlife' , 2.00 , 5.99 , 3.19union allselect 3 , 'Spirit' , 'Leona' , 5.99 , 2.99 , 13.99union allselect 4 , 'Trust Me' ,'Craig David', 7.99 , 11.99 , 6.63union allselect 5 , 'Sawdust' , 'Killers' , 22.99 , 10.99 , 8.39union allselect 6 , 'Greatest Hits' ,'Spice Girls', 12.99 , 0.99 , 13.79select * from @Aselect pos, AlbumTitle, Artist, case WHEN Virgin < WoolWorths AND Virgin < hmv then Virgin WHEN Woolworths < hmv then Woolworths Else hmv END as LowestPrice, case WHEN Virgin < WoolWorths AND Virgin < hmv then 'Virgin' WHEN Woolworths < hmv then 'Woolworths' Else 'hmv' END as LowestLocationfrom @A"God does not play dice" -- Albert Einstein"Not only does God play dice, but he sometimes throws them where they cannot be seen." -- Stephen Hawking |
 |
|
|
|
|
|
|
|