Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 11th, 2007, 06:53 AM
Friend of Wrox
 
Join Date: Apr 2007
Posts: 110
Thanks: 1
Thanked 2 Times in 2 Posts
Send a message via MSN to ayazhoda
Default IFF () in SQL

Hi

I am trying to change IIf([Contacts].[APC]='XXXXX','Deleted','')in this query but don't know to change is SQL as db is transfering to SQL

here's Query

criteria = "SELECT Contacts.Contact, Customers.Customer, Customers.CID, IIf([Contacts].[APC]='XXXXX','Deleted','') AS Status FROM Customers INNER JOIN Contacts ON Customers.CID = Contacts.CID WHERE (Contacts.Contact Like '" & Me!SearchFilter & "*') AND (" & GetCondition("Reps", "rep") & ") ORDER BY Contacts.Contact, Customers.Customer, IIf([Contacts].[APC]='XXXXX','Deleted','');"


Thanks

 
Old July 11th, 2007, 07:21 AM
Friend of Wrox
 
Join Date: Apr 2007
Posts: 110
Thanks: 1
Thanked 2 Times in 2 Posts
Send a message via MSN to ayazhoda
Default

Solution! :)
SELECT Contacts.Contact,
 Customers.Customer,
 Customers.CID,
 CASE WHEN [Contacts].[APC]='XXXXX' THEN 'Deleted' ELSE '' END AS Status
 FROM Customers
INNER JOIN Contacts
ON Customers.CID = Contacts.CID
WHERE (Contacts.Contact Like 'q%')
--AND (" & GetCondition("Reps", "rep") & ")
ORDER BY 1,2,4

 
Old July 11th, 2007, 07:27 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I think that part will work. You want to change Contacts.APC to the string "deleted", otherwise display an empty string?

Also, if you are going to SQL Server, then you should change this to:

criteria = "SELECT Contacts.Contact, Customers.Customer, Customers.CID, IIf([Contacts].[APC]='XXXXX','Deleted','') AS Status FROM Customers INNER JOIN Contacts ON Customers.CID = Contacts.CID WHERE (Contacts.Contact Like '" & Me!SearchFilter & "%') AND (" & GetCondition("Reps", "rep") & ") ORDER BY Contacts.Contact, Customers.Customer, Status"

Note: Change the wildcard * to %, and omit the ";" at the end of the string. Also, in the ORDER BY clause, refer to the alias of the column, not the expression.

I think that will work.

An even better solution would be to build this as a view on the SQL Server since the server will optimize the query, and also reduce data on the wire.

The View would be:

"SELECT Contacts.Contact, Customers.Customer, Customers.CID, IIf([Contacts].[APC]='XXXXX','Deleted','') AS Status
FROM Customers INNER JOIN Contacts ON Customers.CID = Contacts.CID
ORDER BY Contacts.Contact, Customers.Customer, Status"

Then you would do this:

criteria = "WHERE [Contact] Like '" & Me!SearchFilter & "%') AND (" & GetCondition("Reps", "rep") & ")"

Then your SQL string would be:

sSQL = "SELECT * FROM vwMyViewOnSQLServer '" & criteria & "'"

Did that help any?




mmcdonal
 
Old July 11th, 2007, 07:28 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Oh well, forget it then. =)

mmcdonal
 
Old July 17th, 2007, 04:43 AM
Friend of Wrox
 
Join Date: Apr 2007
Posts: 110
Thanks: 1
Thanked 2 Times in 2 Posts
Send a message via MSN to ayazhoda
Default

Thanks very much for that help

 
Old July 17th, 2007, 05:52 AM
Friend of Wrox
 
Join Date: Apr 2007
Posts: 110
Thanks: 1
Thanked 2 Times in 2 Posts
Send a message via MSN to ayazhoda
Default

Hi mmcdonal

In Addition, I found

IIF() doesn't recognize by SQL server so better to change IIF() in CASE and it help as well

Thanks








Similar Threads
Thread Thread Starter Forum Replies Last Post
iff statement not working barmanvarn BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 3 January 23rd, 2009 04:25 PM
calculated control box with iff ultimateace Access 3 January 23rd, 2007 08:40 PM
IFF statement in SQL scott.allison@slp-eng.com SQL Server 2000 1 January 15th, 2007 01:13 PM
Would this be a IFF then Statement Corey Access 7 November 2nd, 2006 03:18 PM
Function Iff in VB 6.0 daninoj Beginning VB 6 2 January 17th, 2005 01:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.