SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how to get max value...
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sadaiyan
Starting Member

India
6 Posts

Posted - 07/28/2008 :  12:33:30  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 07/28/2008 :  12:51:23  Show Profile  Reply with Quote
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
Go to Top of Page

sadaiyan
Starting Member

India
6 Posts

Posted - 07/30/2008 :  12:45:43  Show Profile  Reply with Quote
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)

Singapore
17681 Posts

Posted - 07/30/2008 :  21:03:26  Show Profile  Reply with Quote
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
Time is always against us

Go to Top of Page

sodeep
Flowing Fount of Yak Knowledge

USA
7174 Posts

Posted - 07/30/2008 :  21:19:21  Show Profile  Reply with Quote
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22769 Posts

Posted - 07/31/2008 :  04:58:06  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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
Time is always against us




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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000