I
ironwood9 via AccessMonster.com
I need help re-designing a query to get the desired results that is source by
a query that uses temp/alias fields, from two tables
tblCust
CustID
tblEquipTrans
EquipTransID PK- Autonumber
EqMoveFrom ----- > populated with CustID #
EqMoveTo ----- > populated with CustID #
MoveCode
I need the results to just have three columns – from tblCust, look for match
on CustID in tblEquipTrans, either in the “EqMoveFrom†field, or the
“EqMoveTo†field. I need to show the CustID in the first column that it found
a match to – if it finds the matching number in the “EqMoveFrom†field, or
the “EqMoveTo†field, it doesn’t matter – show the OTHER CustID, and show the
MoveCode for that record. If there is no match, show the custID value, “No
Match†in the second column, and “n/a†or simply null in the third column.
Something like:
CustID……MatchID…..MoveCode
12181………39621…………T
12181……….54896…………C
65488……….NoMatch……(null)
34219……….51322 T
The query I’m trying to alter is q_EquipMoveTwoColumns
It’s based on this query, q_EquipMove:
SELECT DISTINCT C.CustID, T.EqMoveFrom, T.EqMoveTo, T.MoveCode
FROM tblCust AS C LEFT JOIN tblEquipTrans AS T ON C.CustID=T.EqMoveFrom Or C.
CustID=T.EqMoveTo
ORDER BY 1, 2, 3;
The SQL for q_EquipMoveTwoColumns is:
SELECT q_EquipMove.CustID, IIf(IsNull([EqMoveFrom]+[EqMoveTo]),"No Match",IIf
([EqMoveFrom]=[CustID],[EqMoveFrom],[EqMoveTo])) AS EqMove
FROM q_EquipMove;
a query that uses temp/alias fields, from two tables
tblCust
CustID
tblEquipTrans
EquipTransID PK- Autonumber
EqMoveFrom ----- > populated with CustID #
EqMoveTo ----- > populated with CustID #
MoveCode
I need the results to just have three columns – from tblCust, look for match
on CustID in tblEquipTrans, either in the “EqMoveFrom†field, or the
“EqMoveTo†field. I need to show the CustID in the first column that it found
a match to – if it finds the matching number in the “EqMoveFrom†field, or
the “EqMoveTo†field, it doesn’t matter – show the OTHER CustID, and show the
MoveCode for that record. If there is no match, show the custID value, “No
Match†in the second column, and “n/a†or simply null in the third column.
Something like:
CustID……MatchID…..MoveCode
12181………39621…………T
12181……….54896…………C
65488……….NoMatch……(null)
34219……….51322 T
The query I’m trying to alter is q_EquipMoveTwoColumns
It’s based on this query, q_EquipMove:
SELECT DISTINCT C.CustID, T.EqMoveFrom, T.EqMoveTo, T.MoveCode
FROM tblCust AS C LEFT JOIN tblEquipTrans AS T ON C.CustID=T.EqMoveFrom Or C.
CustID=T.EqMoveTo
ORDER BY 1, 2, 3;
The SQL for q_EquipMoveTwoColumns is:
SELECT q_EquipMove.CustID, IIf(IsNull([EqMoveFrom]+[EqMoveTo]),"No Match",IIf
([EqMoveFrom]=[CustID],[EqMoveFrom],[EqMoveTo])) AS EqMove
FROM q_EquipMove;