Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if record exist show field else do not show field 1

Status
Not open for further replies.

evr72

MIS
Dec 8, 2009
265
US
Hello,

I have a query that compares part numbers from one table to another.

Code:
SELECT OPERATIONSTYPE_Crosstab.ITNBR, IIf(OPERATIONSTYPE_Crosstab.ITNBR=OPERATIONS.PARTNUM,OPERATIONS.MATERIAL,OPERATIONSTYPE_Crosstab.DRILL) AS Material
FROM OPERATIONSTYPE_Crosstab LEFT JOIN OPERATIONS ON OPERATIONSTYPE_Crosstab.ITNBR = OPERATIONS.PARTNUM

This gives me
ITNBR PARTNUM Material
0035-U DRILL
0036-03 0036-03 #2308-12 PLENCO


This works well, I am not sure if this can be done but what I would like is if the parts are equal grab the fields from "OPERATIONS" else if they do not match grab the fields from "OPERATIONSTYPE_Crosstab"

If the parts are equal

ITNBR PARTNUM Material INSERT DRILL DRILLQTY
0036-03 0036-03 #2308-12 PLENCO YES YES 1

If the parts are not equal

ITNBR PARTNUM Type1 Type2 Type3
0035-U DRILL CBORE


can this be done?
 
Will you ALWAYS get 2 records out this query?
Can you get just 1 record? Or 17 records?

Have fun.

---- Andy
 
Andrezejek,

it can be more than 1 record
 
Something like this (as a starting point) ?
SELECT T.ITNBR, Nz(O.MATERIAL,T.DRILL) AS Material, Nz(O.INSERT, T.Type1) AS [Insert]
FROM OPERATIONSTYPE_Crosstab T LEFT JOIN OPERATIONS O ON T.ITNBR = O.PARTNUM

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,
Is not exactly what I was looking for but I think that will get me on my way.
what does the "Nz" mean I have not seen that expression before
 
Nz(x,y) equal y if x is null, x otherwise.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top