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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how to get max value...

Author  Topic 

sadaiyan
Starting Member

6 Posts

Posted - 2008-07-28 : 12:33:30
hello, i want to get three fields max value like max(a),max(b) and max(c) and finally i want to get the maximum value of those three value...can anyone suggest a solution please..

sadaiyan.l

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-28 : 12:51:23
[code]SELECT MAX(CASE WHEN Seq=1 THEN [Value] ELSE NULL END) AS MaxA,
MAX(CASE WHEN Seq=2 THEN [Value] ELSE NULL END) AS MaxB,
MAX(CASE WHEN Seq=3 THEN [Value] ELSE NULL END) AS MaxC,
MAX([Value]) AS MaxAll
FROM
(
SELECT a as Value,1 AS Seq
FROM YourTable
UNION ALL
SELECT b,2
FROM YourTable
UNION ALL
SELECT c,3
FROM YourTable
)t[/code]
Go to Top of Page

sadaiyan
Starting Member

6 Posts

Posted - 2008-07-30 : 12:45:43
Hello tkizer,
Thanks to reply me, in this solution what is dt

select max(MaxColumn) as MaxColumn
from
(select max(a) as MaxColumn from table union select max(b) from table union select max(c) from table) dt


sadaiyan.l

sadaiyan.l
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-30 : 21:03:26
quote:
Originally posted by sadaiyan

Hello tkizer,
Thanks to reply me, in this solution what is dt

select max(MaxColumn) as MaxColumn
from
(select max(a) as MaxColumn from table union select max(b) from table union select max(c) from table) dt


sadaiyan.l

sadaiyan.l



Post to the wrong thread ? I don't see Tara's post here


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-07-30 : 21:19:21
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-31 : 04:58:06
quote:
Originally posted by khtan

quote:
Originally posted by sadaiyan

Hello tkizer,
Thanks to reply me, in this solution what is dt

select max(MaxColumn) as MaxColumn
from
(select max(a) as MaxColumn from table union select max(b) from table union select max(c) from table) dt


sadaiyan.l

sadaiyan.l



Post to the wrong thread ? I don't see Tara's post here


KH
[spoiler]Time is always against us[/spoiler]




See here
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=107555

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -