Select Query with an IIf

G

Grace

How would I change this SQL query so that it would select the ClientAFE that
is attached to Project 3470 instead of having to use the AFE number as part
of the query:

SELECT [Bramso Invoices].Invoice, [Bramso Invoices].Date, [Bramso
Invoices].Location, [Bramso Invoices].[Project Type], [Bramso
Invoices].Project, IIf([Project] Is Not
Null,[Projects].[ClientAFE],"0810873") AS AFE
FROM [Bramso Invoices] INNER JOIN Projects ON [Bramso Invoices].Project =
Projects.PENumber;
 
K

KARL DEWEY

Try this --
SELECT [Bramso Invoices].Invoice, [Bramso Invoices].Date, [Bramso
Invoices].Location, [Bramso Invoices].[Project Type], [Bramso
Invoices].Project, [Projects].[ClientAFE]
FROM [Bramso Invoices] INNER JOIN Projects ON [Bramso Invoices].Project =
Projects.PENumber
WHERE [Project] = [Enter Project Number] AND [Bramso Invoices].Project =
[Enter Project Number];
 
G

Grace

My Bramso Invoices table has 100 records. I want my query to attach the AFE
number from the Projects table in the query results. If there is no project
number in a record, I want the AFE client number to default to the AFE number
that is attached to the 3470 project number. This Bramso Invoice table is
imported from an Excel sheet which I may have to import every couple of
months. Instead of having to change the query every time in case the AFE
number for Project 3470 changes, I would like to get the query results to
default to the AFE number that is attached to the 3470 project number if
there is no project number in the Bramso Invoice record.

KARL DEWEY said:
Try this --
SELECT [Bramso Invoices].Invoice, [Bramso Invoices].Date, [Bramso
Invoices].Location, [Bramso Invoices].[Project Type], [Bramso
Invoices].Project, [Projects].[ClientAFE]
FROM [Bramso Invoices] INNER JOIN Projects ON [Bramso Invoices].Project =
Projects.PENumber
WHERE [Project] = [Enter Project Number] AND [Bramso Invoices].Project =
[Enter Project Number];
--
KARL DEWEY
Build a little - Test a little


Grace said:
How would I change this SQL query so that it would select the ClientAFE that
is attached to Project 3470 instead of having to use the AFE number as part
of the query:

SELECT [Bramso Invoices].Invoice, [Bramso Invoices].Date, [Bramso
Invoices].Location, [Bramso Invoices].[Project Type], [Bramso
Invoices].Project, IIf([Project] Is Not
Null,[Projects].[ClientAFE],"0810873") AS AFE
FROM [Bramso Invoices] INNER JOIN Projects ON [Bramso Invoices].Project =
Projects.PENumber;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top