Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

SQL Equivalent of MAX and IIF
I have looked around and found the equivalent for IIF (Access) to be a
SELECT CASE in SQL. I have tried this with no success. I am also looking
for the equivalent of MAX and have had no luck. The portion of the
string I am trying to SQL'ize is:

SELECT Max(IIf([ADCN.ADCN] Is Null,0,[ADCN.ADCN])) AS ADCN FROM ADCN
INNER JOIN Sheet ON ADCN.RecordID = Sheet.RecordID WHERE (Sheet.Drawing
= '" & x & "') AND (Sheet.SheetNumber = 0);


This portion is the most important:
SELECT Max(IIf([ADCN.ADCN] Is Null,0,[ADCN.ADCN])) AS ADCN


*** Sent via Developersdex http://www.droptable.com ***

Report this thread to moderator Post Follow-up to this message
Old Post
Will Chamberlain
11-22-05 01:24 AM


Re: SQL Equivalent of MAX and IIF
MAX is the same in both SQL and Access


Report this thread to moderator Post Follow-up to this message
Old Post
getinked
11-22-05 01:24 AM


Re: SQL Equivalent of MAX and IIF
Will Chamberlain (will.chamberlain@devdex.com)  writes:
> I have looked around and found the equivalent for IIF (Access) to be a
> SELECT CASE in SQL.

SELECT IsThisTrue = CASE WHEN <somecondition> THEN 1 ELSE 0 END

> I have tried this with no success. I am also looking
> for the equivalent of MAX and have had no luck. The portion of the
> string I am trying to SQL'ize is:

For MAX you use CASE as well:

SELECT maxval = CASE WHEN col1 > col2 THEN col1 ELSE col2 END

If it's MAX of two column values. For an aggregate, it's MAX in
SQL Server as well.

> SELECT Max(IIf([ADCN.ADCN] Is Null,0,[ADCN.ADCN])) AS ADCN FROM ADCN[/colo
r]

For "IIf([ADCN.ADCN] Is Null,0,[ADCN.ADCN]" there is a shortcut in
coalesce:

coalesce([ADCN.ADCN], 0)

coalesce accept a list of values and returns the first non-NULL value.




--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

Report this thread to moderator Post Follow-up to this message
Old Post
Erland Sommarskog
11-22-05 01:24 AM


Re: SQL Equivalent of MAX and IIF
Thank you both. I was able to figure it out.

*** Sent via Developersdex http://www.droptable.com ***

Report this thread to moderator Post Follow-up to this message
Old Post
Will Chamberlain
11-22-05 01:24 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 02:50 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006