
max of ("...","...","..")
Sean,
Having posted enough "broken code" on this newsgroup myself, forgive me for
pointing out that your CASE won't work quite the way you want it to.
Specifically, consider the instance when Col1 is greater than Col2, but is
less than Col3. Your case will return Col1 instead of Col3.
Might I suggest the following:
CASE
WHEN Col1 > Col2 AND Col1 > Col3 THEN Col1
WHEN Col2 > Col1 AND Col2 > Col3 THEN Col2
ELSE Col3
END
Quote:
> > I want to return (for each row) the max of three columns, outputing one
> > column.
> > How can I do this in SQL?
> Hmm... maybe with a searched case?
> CASE
> WHEN Col1 > Col2 THEN Col1
> WHEN Col2 > Col3 THEN Col2
> ELSE Col3
> END
> Sorry, don't have a SQL Server in front of me, so I couldn't test it.
> Sean