J
John
I have a make table query that looks great on the screen, but when I run it
some of my number or currency fields get created as text fields in the new
table. How can I get the make table query to match the data type I want? I
tried right-clicking and formating it to currency and/or standard, but it
doesn't seem to work.
Here's the SQL (it's kind of hairy):
SELECT tblMonthly.act AS ActID, Trim([adesc]) AS ActTitle,
tblProjInfo.Period, tblProjInfo.Period_Dte AS Rpt_Dte, tblMonthly.quan_cur AS
BQty, tblMonthly.quan_td AS AQty, tblMonthly.quan_cur-tblMonthly.quan_td AS
RemQty, tblMonthly.um AS UOM, tblMonthly.pcompl_td AS PCT,
tblMonthly.budgt_cur AS BCst, Nz((SELECT TOP 1 tblDupe.budgt_cur FROM
tblMonthly AS tblDupe WHERE tblDupe.act = tblMonthly.act AND tblDupe.FnDte <
tblMonthly.FnDte ORDER BY tblDupe.FnDte Desc, tblDupe.act),0) AS PP_BCst,
[budgt_cur]-Nz((SELECT TOP 1 tblDupe.budgt_cur FROM tblMonthly AS tblDupe
WHERE tblDupe.act = tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER
BY tblDupe.FnDte Desc, tblDupe.act),0) AS Prd_BCst, tblMonthly.ebudgt_td AS
ECst, Nz((SELECT TOP 1 tblDupe.ebudgt_td FROM tblMonthly AS tblDupe WHERE
tblDupe.act = tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY
tblDupe.FnDte Desc, tblDupe.act),0) AS PP_ECst, [ebudgt_td]-Nz((SELECT TOP 1
tblDupe.ebudgt_td FROM tblMonthly AS tblDupe WHERE tblDupe.act =
tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY tblDupe.FnDte
Desc, tblDupe.act),0) AS Prd_ECst, tblMonthly.actualttd AS ACst, Nz((SELECT
TOP 1 tblDupe.actualttd FROM tblMonthly AS tblDupe WHERE tblDupe.act =
tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY tblDupe.FnDte
Desc, tblDupe.act),0) AS PP_ACst, [actualttd]-Nz((SELECT TOP 1
tblDupe.actualttd FROM tblMonthly AS tblDupe WHERE tblDupe.act =
tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY tblDupe.FnDte
Desc, tblDupe.act),0) AS Prd_ACst, tblMonthly.whourbudg AS BHrs, Nz((SELECT
TOP 1 tblDupe.whourbudg FROM tblMonthly AS tblDupe WHERE tblDupe.act =
tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY tblDupe.FnDte
Desc, tblDupe.act),0) AS PP_BHrs, [whourbudg]-Nz((SELECT TOP 1
tblDupe.whourbudg FROM tblMonthly AS tblDupe WHERE tblDupe.act =
tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY tblDupe.FnDte
Desc, tblDupe.act),0) AS Prd_BHrs, nz([whourerntd],0) AS EHrs, Nz((SELECT TOP
1 tblDupe.whourerntd FROM tblMonthly AS tblDupe WHERE tblDupe.act =
tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY tblDupe.FnDte
Desc, tblDupe.act),0) AS PP_EHrs, [whourerntd]-Nz((SELECT TOP 1
tblDupe.whourerntd FROM tblMonthly AS tblDupe WHERE tblDupe.act =
tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY tblDupe.FnDte
Desc, tblDupe.act),0) AS Prd_EHrs, nz([whouracttd],0) AS AHrs, Nz((SELECT TOP
1 tblDupe.whouracttd FROM tblMonthly AS tblDupe WHERE tblDupe.act =
tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY tblDupe.FnDte
Desc, tblDupe.act),0) AS PP_AHrs, [whouracttd]-Nz((SELECT TOP 1
tblDupe.whouracttd FROM tblMonthly AS tblDupe WHERE tblDupe.act =
tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY tblDupe.FnDte
Desc, tblDupe.act),0) AS Prd_AHrs, IIf([AHrs]=0 Or [EHrs]=0,0,[AHrs]/[EHrs])
AS PF_TD INTO tblXTab_CMIS
FROM (tblMonthly LEFT JOIN tblActMap ON tblMonthly.act = tblActMap.Act) LEFT
JOIN tblProjInfo ON tblMonthly.FnDte = tblProjInfo.Period_Dte
ORDER BY tblMonthly.act, tblProjInfo.Period;
some of my number or currency fields get created as text fields in the new
table. How can I get the make table query to match the data type I want? I
tried right-clicking and formating it to currency and/or standard, but it
doesn't seem to work.
Here's the SQL (it's kind of hairy):
SELECT tblMonthly.act AS ActID, Trim([adesc]) AS ActTitle,
tblProjInfo.Period, tblProjInfo.Period_Dte AS Rpt_Dte, tblMonthly.quan_cur AS
BQty, tblMonthly.quan_td AS AQty, tblMonthly.quan_cur-tblMonthly.quan_td AS
RemQty, tblMonthly.um AS UOM, tblMonthly.pcompl_td AS PCT,
tblMonthly.budgt_cur AS BCst, Nz((SELECT TOP 1 tblDupe.budgt_cur FROM
tblMonthly AS tblDupe WHERE tblDupe.act = tblMonthly.act AND tblDupe.FnDte <
tblMonthly.FnDte ORDER BY tblDupe.FnDte Desc, tblDupe.act),0) AS PP_BCst,
[budgt_cur]-Nz((SELECT TOP 1 tblDupe.budgt_cur FROM tblMonthly AS tblDupe
WHERE tblDupe.act = tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER
BY tblDupe.FnDte Desc, tblDupe.act),0) AS Prd_BCst, tblMonthly.ebudgt_td AS
ECst, Nz((SELECT TOP 1 tblDupe.ebudgt_td FROM tblMonthly AS tblDupe WHERE
tblDupe.act = tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY
tblDupe.FnDte Desc, tblDupe.act),0) AS PP_ECst, [ebudgt_td]-Nz((SELECT TOP 1
tblDupe.ebudgt_td FROM tblMonthly AS tblDupe WHERE tblDupe.act =
tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY tblDupe.FnDte
Desc, tblDupe.act),0) AS Prd_ECst, tblMonthly.actualttd AS ACst, Nz((SELECT
TOP 1 tblDupe.actualttd FROM tblMonthly AS tblDupe WHERE tblDupe.act =
tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY tblDupe.FnDte
Desc, tblDupe.act),0) AS PP_ACst, [actualttd]-Nz((SELECT TOP 1
tblDupe.actualttd FROM tblMonthly AS tblDupe WHERE tblDupe.act =
tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY tblDupe.FnDte
Desc, tblDupe.act),0) AS Prd_ACst, tblMonthly.whourbudg AS BHrs, Nz((SELECT
TOP 1 tblDupe.whourbudg FROM tblMonthly AS tblDupe WHERE tblDupe.act =
tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY tblDupe.FnDte
Desc, tblDupe.act),0) AS PP_BHrs, [whourbudg]-Nz((SELECT TOP 1
tblDupe.whourbudg FROM tblMonthly AS tblDupe WHERE tblDupe.act =
tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY tblDupe.FnDte
Desc, tblDupe.act),0) AS Prd_BHrs, nz([whourerntd],0) AS EHrs, Nz((SELECT TOP
1 tblDupe.whourerntd FROM tblMonthly AS tblDupe WHERE tblDupe.act =
tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY tblDupe.FnDte
Desc, tblDupe.act),0) AS PP_EHrs, [whourerntd]-Nz((SELECT TOP 1
tblDupe.whourerntd FROM tblMonthly AS tblDupe WHERE tblDupe.act =
tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY tblDupe.FnDte
Desc, tblDupe.act),0) AS Prd_EHrs, nz([whouracttd],0) AS AHrs, Nz((SELECT TOP
1 tblDupe.whouracttd FROM tblMonthly AS tblDupe WHERE tblDupe.act =
tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY tblDupe.FnDte
Desc, tblDupe.act),0) AS PP_AHrs, [whouracttd]-Nz((SELECT TOP 1
tblDupe.whouracttd FROM tblMonthly AS tblDupe WHERE tblDupe.act =
tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY tblDupe.FnDte
Desc, tblDupe.act),0) AS Prd_AHrs, IIf([AHrs]=0 Or [EHrs]=0,0,[AHrs]/[EHrs])
AS PF_TD INTO tblXTab_CMIS
FROM (tblMonthly LEFT JOIN tblActMap ON tblMonthly.act = tblActMap.Act) LEFT
JOIN tblProjInfo ON tblMonthly.FnDte = tblProjInfo.Period_Dte
ORDER BY tblMonthly.act, tblProjInfo.Period;