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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 GREATEST AND LEAST

Author  Topic 

vishu.av
Starting Member

26 Posts

Posted - 2007-04-24 : 02:32:31
Hi All,

Is there any equivalent of GREATEST(something) and LEAST(something)
in SQL server 2000

Thanks in advance.

vishu
Bangalore

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-24 : 03:08:07
MAX and MIN.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

vishu.av
Starting Member

26 Posts

Posted - 2007-04-24 : 04:33:01
Hi Peter,
Thanks for the response.
Infact i have more than 1 value in my list.
I mean i have to select the largest of values from a group or list which contain one value as a column name and other as some integer values.
GREATEST( a,b,c..) and 'a' being a column of a table with numeric value.



vishu
Bangalore
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-24 : 04:38:59
I knew it was not that simple!

Something like this?

select max(a), min(a) from
(Select max(a) as a from table
union all
select <b> -- <b> represents some numeric value here
union all
select <c> -- <c> represents some numeric value here
) temp


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-24 : 04:47:08
<b> and <c> are from what table


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-24 : 04:48:27
select max(value), min(value) from
(Select a as value from table
union all
select b from table
union all
select c from table
) as t


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-24 : 04:50:09
quote:
Originally posted by Peso

<b> and <c> are from what table


Peter Larsson
Helsingborg, Sweden



That's why I put the comments..they are not from the table, those are numeric literals.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-24 : 04:54:21
Ahh, I see.
Is MAX(a) equal to MIN(a), when first calculating MAX(a) AS a in derived table?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-24 : 04:57:25
quote:
Originally posted by Peso

Ahh, I see.
Is MAX(a) equal to MIN(a), when first calculating MAX(a) AS a in derived table?


Peter Larsson
Helsingborg, Sweden



Oh..I see the error there...Initially I was just thinking about max value there.

select max(a), min(a) from
(Select a as a from table
union all
select <b> -- <b> represents some numeric value here
union all
select <c> -- <c> represents some numeric value here
) temp


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

vishu.av
Starting Member

26 Posts

Posted - 2007-04-24 : 06:04:15
Thanks for the reply


vishu
Bangalore
Go to Top of Page
   

- Advertisement -