I have a database with 2 tables
SAP_Data
Old_MM WI_1 WI_2 ..... WI_15
12345 1 2
23456 1 10
34567 2 3
WI
ID WI
1 Clean
2 take to lab
3 Filter
.
.
.
What I need to do is make a query that selects the WI based on the number in WI_1, WI_2... and have it be in the right order.
I've come up with a select & union query
SELECT SAP_Data.Old_MM, WI.WI
FROM WI, SAP_Data
WHERE (((WI.ID)=[SAP_Data].[WI_1]))
UNION ALL Select SAP_Data.Old_MM, WI.WI
From WI, SAP_Data
Where (((WI.ID)=[SAP_Data].[WI_2]))
UNION ALL Select SAP_Data.Old_MM, WI.WI
From WI, SAP_Data
Where (((WI.ID)=[SAP_Data].[WI_3]))
UNION ALL Select SAP_Data.Old_MM, WI.WI
From WI, SAP_Data
Where (((WI.ID)=[SAP_Data].[WI_4]))
UNION ALL Select SAP_Data.Old_MM, WI.WI
From WI, SAP_Data
Where (((WI.ID)=[SAP_Data].[WI_5]))
UNION ALL Select SAP_Data.Old_MM, WI.WI
From WI, SAP_Data
Where (((WI.ID)=[SAP_Data].[WI_6]))
UNION ALL Select SAP_Data.Old_MM, WI.WI
From WI, SAP_Data
Where (((WI.ID)=[SAP_Data].[WI_7]))
UNION ALL Select SAP_Data.Old_MM, WI.WI
From WI, SAP_Data
Where (((WI.ID)=[SAP_Data].[WI_8]))
UNION ALL Select SAP_Data.Old_MM, WI.WI
From WI, SAP_Data
Where (((WI.ID)=[SAP_Data].[WI_9]))
UNION ALL Select SAP_Data.Old_MM, WI.WI
From WI, SAP_Data
Where (((WI.ID)=[SAP_Data].[WI_10]))
UNION ALL Select SAP_Data.Old_MM, WI.WI
From WI, SAP_Data
Where (((WI.ID)=[SAP_Data].[WI_11]))
UNION ALL Select SAP_Data.Old_MM, WI.WI
From WI, SAP_Data
Where (((WI.ID)=[SAP_Data].[WI_12]))
UNION ALL Select SAP_Data.Old_MM, WI.WI
From WI, SAP_Data
Where (((WI.ID)=[SAP_Data].[WI_13]))
UNION ALL Select SAP_Data.Old_MM, WI.WI
From WI, SAP_Data
Where (((WI.ID)=[SAP_Data].[WI_14]))
UNION Select SAP_Data.Old_MM, WI.WI
From WI, SAP_Data
Where (((WI.ID)=[SAP_Data].[WI_15]));
This does work but I can't for the life of me get it in the correct order. It all comes out seemingly random.
I've tried doing them all in separate queries but when I add them together it won't show the ones that are null.
If there is a better way to do this please let me know. I'm new to access and know very little SQL or VBA. I tried to upload the database but it's way too big.
Thanks, Sarah