all groups > sql server data warehouse > june 2004 >
You're in the

sql server data warehouse

group:

Finding the Max value in a query


Finding the Max value in a query Duvon Harper
6/15/2004 11:37:57 AM
sql server data warehouse:
Hello,
I am tring to write a query to show the Max value of
several columns. I would like to store that value in a
new column. Please help I can not write this.

Duvon Harper
Re: Finding the Max value in a query Adam Machanic
6/15/2004 2:52:18 PM
You could write a bunch of CASE logic... But if you have several columns to
compare I think it's easier to do something like:

SELECT MAX(cols), rowid
FROM (
SELECT col1 AS cols, rowid FROM yourtable
UNION ALL
SELECT col2 AS cols, rowid FROM yourtable
...
) x (cols, rowid)


[quoted text, click to view]

AddThis Social Bookmark Button