我有一个表,其中一些字段是 char(2)。如果字段只有 1 个字符长,则某些字段需要前导 0(零)。我创建了一个查询,我尝试了几种不同的格式化方法来实现左侧填充。这些尝试在查看查询结果时工作正常,但是当我检查导出时创建的文本文件时,相关字段不包含前导 0。
这是我在查询中使用的两种方法
`FORMAT(tblMHOutcome.Dayscom, "00") AS Dayscom`
`IIF(LEN(tblMHOutcome.Daysatte)=1, "0"&tblMHOutcome.Daysatte`
下图显示了导出窗口中的视图,其中填充了字段:
下面是没有字段填充的生成文本文件的图像:
关于如何在格式化后导出查询的任何建议?
更新:添加了完整查询
`SELECT tblMHOutcome.ContractorID, tblMHOutcome.SiteID, tblMHOutcome.SSN,
tblMHOutcome.ClientID, tblMHOutcome.Purpeval, tblMHOutcome.Evaldate,
tblMHOutcome.StaffID, tblMHOutcome.Initevada, tblMHOutcome.Pincosrc,
tblMHOutcome.Disincom, tblMHOutcome.Prognosis, tblMHOutcome.Depcrims,
tblMHOutcome.Admitype, FORMAT(tblMHOutcome.Dayscom, "00") AS Dayscom,
FORMAT(tblMHOutcome.Dayswork, "00") AS Dayswork, tblMHOutcome.Incopay,
tblMHOutcome.Incogov, tblMHOutcome.Incother, tblMHOutcome.GAF,
IIF(LEN(tblMHOutcome.Daysavai)=1, "0"&tblMHOutcome.Daysavai, tblMHOutcome.Daysavai) AS
Daysavai, IIF(LEN(tblMHOutcome.Daysatte)=1, "0"&tblMHOutcome.Daysatte,
tblMHOutcome.Daysatte) AS Daysatte, IIF(LEN(tblMHOutcome.CGAS)=1,
"0"&tblMHOutcome.CGAS, tblMHOutcome.CGAS) AS CGAS, tblMHOutcome.DJJComit,
tblMHOutcome.Riskfact, tblMHOutcome.Residstat, tblMHOutcome.Marital, tblMHOutcome.Empl,
tblMHOutcome.Residcont, tblMHOutcome.Grade, tblMHOutcome.Rx, tblMHOutcome.Develop,
tblMHOutcome.Physical, tblMHOutcome.Ambulat, tblMHOutcome.Visual, tblMHOutcome.Hearing,
tblMHOutcome.English, tblMHOutcome.ADLFC, tblMHOutcome.Provinfo, tblMHOutcome.Zip,
tblMHOutcome.Tstat, tblMHOutcome.Famsize, tblMHOutcome.MHProb, tblMHOutcome.Faminc,
tblMHOutcome.Referral, tblMHOutcome.Provid, tblMHOutcome.MHDiagnosis,
tblMHOutcome.SADiagnosis, tblMHOutcome.Bakeract, tblMHOutcome.Rxidp,
tblMHOutcome.Rxpap, tblMHOutcome.Contnum1, tblMHOutcome.Contnum2,
tblMHOutcome.Contnum3, tblMHOutcome.Vetstatus, tblMHOutcome.Social,
tblMHOutcome.School, tblMHOutcome.Arrest
FROM tblMHOutcome
WHERE (((tblMHOutcome.DeleteRecord)=False))
ORDER BY tblMHOutcome.Evaldate;`
和 VBA 代码:
`DoCmd.TransferText acExportFixed, "MHOutcomeExport", "qryMHOutcomeExport", "Exports\MHOutcome.txt", False`