Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 11th, 2007, 06:53 AM
Friend of Wrox
 
Join Date: Apr 2007
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old July 11th, 2007, 07:21 AM
Friend of Wrox
 
Join Date: Apr 2007
Location: , , .
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

Reply With Quote
  #3 (permalink)  
Old July 11th, 2007, 07:27 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
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
Reply With Quote
  #4 (permalink)  
Old July 11th, 2007, 07:28 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Oh well, forget it then. =)

mmcdonal
Reply With Quote
  #5 (permalink)  
Old July 17th, 2007, 04:43 AM
Friend of Wrox
 
Join Date: Apr 2007
Location: , , .
Posts: 110
Thanks: 1
Thanked 2 Times in 2 Posts
Send a message via MSN to ayazhoda
Default

Thanks very much for that help

Reply With Quote
  #6 (permalink)  
Old July 17th, 2007, 05:52 AM
Friend of Wrox
 
Join Date: Apr 2007
Location: , , .
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



Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:41 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.