Solved

access if-statement

Posted on 2008-10-16
5
813 Views
Last Modified: 2012-08-14
please give me the complete SQL to make an if-statement (with the field name "T/C") based on the following criteria and add it to  the attached code snippet
1.  if the field called "cust_ID" is not null in both "table C and table T, then I want the record to say "C/T"
2.  if  "cust_ID" is null in table C, but not null  in table T, then I want it to say "T"
3. if  "cust_ID" is null in table T, but not null  in table C, then I want it to say "C"

thank you very much
SELECT M.cust_ID

FROM qryConverterTransCustomers_01 AS C RIGHT JOIN (qryConverterTransCustomers_02 AS T RIGHT JOIN tmpMasterTable AS M ON T.cust_ID = M.cust_ID) ON C.cust_ID = M.cust_ID;

Open in new window

0
Comment
Question by:gringotani
  • 3
  • 2
5 Comments
 
LVL 39

Expert Comment

by:BrandonGalderisi
Comment Utility
Will c.cust_id AND t.cust_id ever be null?  If so, neither will be displayed with this query.  Regardless, this should handle C, T or T/C.

SELECT M.cust_ID
,iif(c.cust_id is not null, iif(m.cust_id is not null, 'T/C', 'C'), iif(m.cust_id is not null,'T','NEITHER'))
FROM qryConverterTransCustomers_01 AS C RIGHT JOIN (qryConverterTransCustomers_02 AS T RIGHT JOIN tmpMasterTable AS M ON T.cust_ID = M.cust_ID) ON C.cust_ID = M.cust_ID;

0
 

Author Comment

by:gringotani
Comment Utility
Hi, thanks for answering my question.  Your SQl doesnt exactly match my conditons.  pls fix.  
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
Comment Utility
Well if you tell me what it is/isn't doing that would make it a lot easier?
0
 

Author Comment

by:gringotani
Comment Utility
the purpose of the if statement is to tell me if csut-ID is present in either table T or C. the if statement should not contain table M.  
1.  if the field called "cust_ID" is not null in both "table C and table T, then I want the record to say "C/T"
2.  if  "cust_ID" is null in table C, but not null  in table T, then I want it to say "T"
3. if  "cust_ID" is null in table T, but not null  in table C, then I want it to say "C"

thank you very much
0
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 50 total points
Comment Utility
Got it.  And do you want t/c or c/t.  Because you said t/c at first and c/t now.  Or doesn't it matter?

This should do it.
SELECT M.cust_ID

,iif(c.cust_id is not null, iif(t.cust_id is not null, 'T/C', 'C'), iif(t.cust_id is not null,'T','NEITHER'))

FROM qryConverterTransCustomers_01 AS C RIGHT JOIN (qryConverterTransCustomers_02 AS T RIGHT JOIN tmpMasterTable AS M ON T.cust_ID = M.cust_ID) ON C.cust_ID = M.cust_ID;

Open in new window

0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now