J
juicegully
I have two tables, tbBulk and tbAtts. Some sample data include:
tbBulk:
Name, AttrName, AttrValue (Field names)
Apple, Num, 1
Apple, Addr1, 2
Apple, Addr2, 3
Banana, Dwg, 4
Banana, Addr1, 5
Banana, Addr2, 6
tbAtts is initially blank. I run an append query which populates tbAtts to
look like:
tbAtts:
Name, DrawingNo, AddrNo
Apple, 1, _
Banana, 4, _
where the underscore is an empty field.
The append query is:
INSERT INTO Atts ( Name, DrawingNo )
SELECT [Name], [AttrValue]
FROM tbBulk
WHERE (AttrName='Num' Or AttrName='Dwg');
So now I need to fill in the AddrNo column in tbAtts. The requirements are
that for each fruit, if the AttrName is Num, the Attrvalue to be used should
come from the row where AttrName is Addr1. If the AttrName is Dwg, the
Attrvalue to be used should come from the row where AttrName is Addr2.
The final data should look like this:
tbAtts:
Name, DrawingNo, AddrNo
Apple, 1, 2
Banana, 4, 6
I'm really stuck! So far my update query looks like this:
UPDATE tbAtts INNER JOIN tbBulk ON tbAtts.Name=tbBulk.Name SET tbAtts.AddrNo
= tbBulk.AttrValue
WHERE tbBulk.AttrName=IIF(tbBulk.AttrName='Num','Addr1','Addr2') And Not
IsNull(tbBulk.AttrValue) And tbBulk.AttrValue<>'';
Any help is greatly appreciated!
Thank you.
tbBulk:
Name, AttrName, AttrValue (Field names)
Apple, Num, 1
Apple, Addr1, 2
Apple, Addr2, 3
Banana, Dwg, 4
Banana, Addr1, 5
Banana, Addr2, 6
tbAtts is initially blank. I run an append query which populates tbAtts to
look like:
tbAtts:
Name, DrawingNo, AddrNo
Apple, 1, _
Banana, 4, _
where the underscore is an empty field.
The append query is:
INSERT INTO Atts ( Name, DrawingNo )
SELECT [Name], [AttrValue]
FROM tbBulk
WHERE (AttrName='Num' Or AttrName='Dwg');
So now I need to fill in the AddrNo column in tbAtts. The requirements are
that for each fruit, if the AttrName is Num, the Attrvalue to be used should
come from the row where AttrName is Addr1. If the AttrName is Dwg, the
Attrvalue to be used should come from the row where AttrName is Addr2.
The final data should look like this:
tbAtts:
Name, DrawingNo, AddrNo
Apple, 1, 2
Banana, 4, 6
I'm really stuck! So far my update query looks like this:
UPDATE tbAtts INNER JOIN tbBulk ON tbAtts.Name=tbBulk.Name SET tbAtts.AddrNo
= tbBulk.AttrValue
WHERE tbBulk.AttrName=IIF(tbBulk.AttrName='Num','Addr1','Addr2') And Not
IsNull(tbBulk.AttrValue) And tbBulk.AttrValue<>'';
Any help is greatly appreciated!
Thank you.