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
 General SQL Server Forums
 New to SQL Server Programming
 Emmulating Excel Max(IF) in SQL
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

GPSPOW
Starting Member

USA
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?

Glen

jimf
Flowing Fount of Yak Knowledge

USA
2869 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)

Jim

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

madhivanan
Premature Yak Congratulator

India
22713 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

Madhivanan

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

visakh16
Very Important crosS Applying yaK Herder

India
52249 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
http://visakhm.blogspot.com/


Edited by - visakh16 on 01/07/2013 09:34:30
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.05 seconds. Powered By: Snitz Forums 2000