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
 COMPARING WITH COLUM WITH SPECIFIC VALUES IN SQL

Author  Topic 

Limuh
Yak Posting Veteran

94 Posts

Posted - 2008-02-06 : 07:53:17
Im Working with stored procedure. How can i compare Columns with specific values. I want to get the greater values of those column and inserted it to other columns. i want something like these
CASE
WHEN a> b,c,d THEN a
WHEN b> a,c,d THEN b
WHEN c> a,b,d THEN c
WHEN d> a,d,c THEN d

is there any ways to implement this? i got an error..
thanks please help..

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2008-02-06 : 08:34:22
select max(a), max(b), max(c), max(d) from table
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-06 : 08:48:22
[code]
select
case
when a>b and a>c and a>d then a
when b>c and b>d then b
when c>d then c
else d
end
from your_table[/code]

Madhivanan

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

Limuh
Yak Posting Veteran

94 Posts

Posted - 2008-02-06 : 22:44:44
Thanks i do appreciate it a lot..
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-07 : 07:09:24
quote:
Originally posted by Limuh

Thanks i do appreciate it a lot..


Which one?

Madhivanan

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

Limuh
Yak Posting Veteran

94 Posts

Posted - 2008-02-12 : 22:23:23
yours madhivanan
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-13 : 01:38:58
Also see

MIN/MAX Across Multiple Columns
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=86906



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Limuh
Yak Posting Veteran

94 Posts

Posted - 2008-02-13 : 02:56:51
Thanks
Go to Top of Page
   

- Advertisement -