How to merge these 2 queries

D

DawnTreader

Here comes some hefty SQL code:

qryNewRebuildReport

SELECT
tblproductpartlist.productid,
tblproductpartlist.imwpartnumberid,
tblproductpartlist.onekmaint,
tblproductpartlist.fivekrebuild,
tblproductpartlist.tenkrebuild,
tblproductpartlist.ftkrebuild,
tblproductpartlist.twkrebuild,
tblproductpartlist.twfkthourebuild,
tblproductpartlist.thkrebuild,
tblproductpartlist.thfkrebuild,
tblproductpartlist.ftykrebuild
FROM
tblproductpartlist
WHERE ( ( ( tblproductpartlist.productid ) = 1935 )
AND ( ( tblproductpartlist.onekmaint ) = "y" ) )
OR ( ( ( tblproductpartlist.productid ) = 1935 )
AND ( ( tblproductpartlist.fivekrebuild ) = "y" ) )
OR ( ( ( tblproductpartlist.productid ) = 1935 )
AND ( ( tblproductpartlist.tenkrebuild ) = "y" ) )
OR ( ( ( tblproductpartlist.productid ) = 1935 )
AND ( ( tblproductpartlist.ftkrebuild ) = "y" ) )
OR ( ( ( tblproductpartlist.productid ) = 1935 )
AND ( ( tblproductpartlist.twkrebuild ) = "y" ) )
OR ( ( ( tblproductpartlist.productid ) = 1935 )
AND ( ( tblproductpartlist.twfkthourebuild ) = "y" ) )
OR ( ( ( tblproductpartlist.productid ) = 1935 )
AND ( ( tblproductpartlist.thkrebuild ) = "y" ) )
OR ( ( ( tblproductpartlist.productid ) = 1935 )
AND ( ( tblproductpartlist.thfkrebuild ) = "y" ) )
OR ( ( ( tblproductpartlist.productid ) = 1935 )
AND ( ( tblproductpartlist.ftykrebuild ) = "y" ) );


i am figureing i need to do a sub query, but how do i get the above to work
with the below:

SELECT qrynewrebuildreport.productid,
qrynewrebuildreport.imwpartnumberid,
qrynewrebuildreport.onekmaint,
"1 1000 Hr Service" AS intervaldescription,
1000 AS intervallink
FROM qrynewrebuildreport
WHERE (( ( qrynewrebuildreport.onekmaint ) = "y" ))
Union SELECT qrynewrebuildreport.productid,
qrynewrebuildreport.imwpartnumberid,
qrynewrebuildreport.fivekrebuild,
"2 5000 Hr Rebuild" AS intervaldescription,
5000 AS intervallink
FROM qrynewrebuildreport
WHERE (( ( qrynewrebuildreport.fivekrebuild ) = "y" ))
Union SELECT qrynewrebuildreport.productid,
qrynewrebuildreport.imwpartnumberid,
qrynewrebuildreport.tenkrebuild,
"3 10000 Hr Rebuild" AS intervaldescription,
10000 AS intervallink
FROM qrynewrebuildreport
WHERE (( ( qrynewrebuildreport.tenkrebuild ) = "y" ))
Union SELECT qrynewrebuildreport.productid,
qrynewrebuildreport.imwpartnumberid,
qrynewrebuildreport.ftkrebuild,
"4 15000 Hr Rebuild" AS intervaldescription,
15000 AS intervallink
FROM qrynewrebuildreport
WHERE (( ( qrynewrebuildreport.ftkrebuild ) = "y" ))
Union SELECT qrynewrebuildreport.productid,
qrynewrebuildreport.imwpartnumberid,
qrynewrebuildreport.twkrebuild,
"5 20000 Hr Rebuild" AS intervaldecription,
20000 AS intervallink
FROM qrynewrebuildreport
WHERE (( ( qrynewrebuildreport.twkrebuild ) = "y" ))
Union SELECT qrynewrebuildreport.productid,
qrynewrebuildreport.imwpartnumberid,
qrynewrebuildreport.twfkthourebuild,
"6 25000 Hr Rebuild" AS intervaldescription,
25000 AS intervallink
FROM qrynewrebuildreport
WHERE (( ( qrynewrebuildreport.twfkthourebuild ) = "y" ))
Union SELECT qrynewrebuildreport.productid,
qrynewrebuildreport.imwpartnumberid,
qrynewrebuildreport.thkrebuild,
"7 30000 Hr Rebuild" AS intervaldescription,
30000 AS intervallink
FROM qrynewrebuildreport
WHERE (( ( qrynewrebuildreport.thkrebuild ) = "y" ))
Union SELECT qrynewrebuildreport.productid,
qrynewrebuildreport.imwpartnumberid,
qrynewrebuildreport.thfkrebuild,
"8 35000 Hr Rebuild" AS intervaldescription,
35000 AS intervallink
FROM qrynewrebuildreport
WHERE (( ( qrynewrebuildreport.thfkrebuild ) = "y" ))
UNION SELECT qrynewrebuildreport.productid,
qrynewrebuildreport.imwpartnumberid,
qrynewrebuildreport.ftykrebuild,
"9 40000 Hr Rebuild" AS intervaldescription,
40000 AS intervallink
FROM qrynewrebuildreport
WHERE (( ( qrynewrebuildreport.ftykrebuild ) = "y" ));
 

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