Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Emmulating Excel Max(IF) in SQL
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

5 Posts

Posted - 01/06/2013 :  13:17:01  Show Profile  Reply with Quote
I have a spreadsheet table derived from a SQL view. I perform an ARRAY function on the table where I determine the MAX value of a column of values based on the value in another row column:

{MAX(IF( lookuprange=cellvalue,rangevalues ))}

How can write a SQL statement to emulate this function in the original view?


Flowing Fount of Yak Knowledge

2875 Posts

Posted - 01/06/2013 :  15:11:49  Show Profile  Reply with Quote
Not really enough to go on here, but something like MAX(CASE WHEN COL1 IN (Val1,Val2, etc.) THEN COL2 ELSE someOtherValue END)


Everyday I learn something that somebody else already knew
Go to Top of Page

Premature Yak Congratulator

22864 Posts

Posted - 01/07/2013 :  07:47:41  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
If you use version 2012, you can use IIF function in the same way used in EXCEL


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

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 01/07/2013 :  09:33:48  Show Profile  Reply with Quote
the lookuprange can only be simulated by join in t-sql.
then you can use something like jimf showed or using IIF if sql 2012

SQL Server MVP

Edited by - visakh16 on 01/07/2013 09:34:30
Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000