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 |
|
nhess80
Yak Posting Veteran
83 Posts |
Posted - 2008-06-02 : 14:09:17
|
| Im having trouble finding a solution to comparing columns to find the lowest value.ExampleRow 1 COL 1 = 10COL 2 = 20COL 3 = 60COL 4 = 5COL 5 = 35I would want to return 5.I tried to write a case statement such as below but am unable to use Logical Operators.WHEN C1 <= C2 and C1<= C3 THEN C1WHEN C2 <= C3 THEN C2ELSE C3any help would be great.Thanks,Nick |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-02 : 14:15:16
|
| [code]SELECT t.PKcol,MIN(t.ColValue)FROM ( SELECT PKCol,Col1 AS ColValue FROM YourTable UNION ALL SELECT PKCol,Col2 FROM YourTable UNION ALL SELECT PKCol,Col3 FROM YourTable UNION ALL SELECT PKCol,Col4 FROM YourTable UNION ALL SELECT PKCol,Col5 FROM YourTable)tGROUP BY t.PKCol[/code] |
 |
|
|
|
|
|