Re: Select Query; if statement in one field?
- From: "Ken Snell \(MVP\)" <kthsneisllis9@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 9 Oct 2008 16:28:24 -0400
You'll need a union query that uses tthree queries that join on one or the
other field, or ignore the join. But, you cannot do this in Design view,
though. A Union query can be entered only in SQL view.
Open a new query, select no tables, close the table selection window, and
then click on View icon on toolbar and select SQL View.
This query will get you close:
SELECT VendorList.vendorName, VendorList.vendorCode,
VendorList.acctRepCode, AcctRepList.repLastName,
AcctRepList.repFirstName, AcctRepList.rep3digitCode,
AcctRepList.rep2digitCode
FROM AcctRepList INNER JOIN VendorList
ON AcctRepList.rep2digitCode = VendorList.acctRepCode;
UNION ALL
SELECT VendorList.vendorName, VendorList.vendorCode,
VendorList.acctRepCode, AcctRepList.repLastName,
AcctRepList.repFirstName, AcctRepList.rep3digitCode,
AcctRepList.rep2digitCode
FROM AcctRepList INNER JOIN VendorList
ON AcctRepList.rep3digitCode = VendorList.acctRepCode;
UNION ALL
SELECT VendorList.vendorName, VendorList.vendorCode,
"Invalid Rep Code" AS acctRepCode, NULL,
NULL, NULL,
NULL
FROM AcctRepList
WHERE VendorList.acctRepCode IS NULL;
--
Ken Snell
<MS ACCESS MVP>
"Susan" <Susan@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:D0B65864-10B3-4A86-AE32-6689F2D5055C@xxxxxxxxxxxxxxxx
I apologize in advance if this was covered elsewhere, I wasn't quite sure
how
to word my search on this.
I have 2 tables with the following fields:
- VendorList ( vendorName, vendorCode, acctRepCode )
- AcctRepList ( repLastName, repFirstName, rep3digitCode, rep2digitCode)
Basically the Account Rep codes used to be 2 digits for a long time, but
for
expansion purposes and future purposes we have moved over to using 3 digit
codes. The problem is that, some rep codes have been updated to the 3
digit,
some have been left alone with the 2 digit code.
I'm working in Design mode, so please keep this in mind, as my SQL coding
skills are not that great.
My question is--is there a way to do this:
I wanted to query a VendorList.vendorCode with AcctRepList.repLastName
For AcctRepList.repLastName, I want it to first see if
VendorList.acctRepCode is Null, 2, or 3 digits
if Null, fill field with "Invalid Rep Code"
if 2 digits, try to join with AcctRepList.rep2digitCode
if 3 digits, try to join with AcctRepList.rep3digitCode
All of this--for one field.
Is this possible?
Thanks in advance!
Susan
.
- Follow-Ups:
- Re: Select Query; if statement in one field?
- From: Ken Snell \(MVP\)
- Re: Select Query; if statement in one field?
- References:
- Select Query; if statement in one field?
- From: Susan
- Select Query; if statement in one field?
- Prev by Date: Basic math
- Next by Date: Re: Lookup product price
- Previous by thread: Select Query; if statement in one field?
- Next by thread: Re: Select Query; if statement in one field?
- Index(es):
Relevant Pages
|