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 2000 Forums
 Transact-SQL (2000)
 Find highest values from 3 filelds

Author  Topic 

ramecepa
Starting Member

43 Posts

Posted - 2010-08-30 : 00:07:56
Dear all,
i want to find highest value from 3 fields
EX:
field1 field2 field3
0 0 1

2 3 1

5 4 2

Result
1
3
5

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-08-30 : 01:47:55

Select case when f1 > f2 and f1 > f3 then f1
when f2 > f3 then f2 else f3 end from field

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

ramecepa
Starting Member

43 Posts

Posted - 2010-08-30 : 02:06:17
select case when piaprin > piaint > pialpi then piaprin
when piaint > pialpi then piaint
else pialpi end as ta from tbl_Aces1


i have written like this ....getting error like
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '>'.
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-08-30 : 02:14:29
quote:
Originally posted by ramecepa

select case when piaprin > piaint and piaprin > pialpi then piaprin
when piaint > pialpi then piaint
else pialpi end as ta from tbl_Aces1


i have written like this ....getting error like
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '>'.



Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

ramecepa
Starting Member

43 Posts

Posted - 2010-08-30 : 02:36:37
Thanks bro,
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2010-08-30 : 02:39:54
It mightn't work if columns are null.
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-08-30 : 02:40:38
quote:
Originally posted by ramecepa

Thanks bro,



Welcome!

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-08-30 : 02:41:34
quote:
Originally posted by sakets_2000

It mightn't work if columns are null.



If the case ,we must use isnull(column_name,0)

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2010-08-30 : 02:52:16
What if you had 10 columns instead ?? That'd be a lot of combinations.

Method 1 from this link is a better way to do this..
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=86906
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-08-30 : 02:59:45
quote:
Originally posted by sakets_2000

What if you had 10 columns instead ?? That'd be a lot of combinations.

Method 1 from this link is a better way to do this..
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=86906



Ya ofcourse, but here the case no of columns are fixed and solution is acceptable!

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page
   

- Advertisement -