SQL Server Performance

how do I compare 3 columns to find the lowest value?

Discussion in 'SQL Server 2005 General Developer Questions' started by kingofSQL, Apr 9, 2008.

  1. kingofSQL New Member

    Any ideas on how to tackle this using SQL:
    column A = 10
    column B = 20
    column C = 30
    column D = the lowest value of the 3 columns (which would be 10)
    thanks all in advance!
  2. jagblue New Member

    You can create table like his
    C1 INT,
    C2 INT,
    C3 INT,
    C4 AS (CASE
    WHEN C1 <= C2 and C1<= C3 THEN C1
    WHEN C2 <= C3 THEN C2
    ELSE C3
    adt then Insert the values in table
    INSERT Test VALUES(10,20,30)
    SELECT * FROM Test
  3. kingofSQL New Member

    thanks jagblue
    I think I simplified things a bit. The actual table has 16 columns that I need to compare to find the lowest value out of those 16 columns. I think a CASE statement might be too much.
    any other ideas welcome
  4. madhuottapalam New Member

Share This Page