我有一个表格,其中一些字段是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`
答案 0 :(得分:1)
您可以使用:
SELECT Format(ANumber,"00") AS Expr1
INTO [Text;FMT=Fixed;DATABASE=Z:\docs].[exp.txt]
FROM table1;
schema.ini可以提供帮助。例如,Handle TransferText Errors
或者,这将创建一个两位数字:
SELECT Right("00" & Anumber,2)
FROM Table1;
和
DoCmd.TransferText acExportFixed, "expspec", "Query3", "z:\docs\exp.txt"
重新评论
SELECT IIf(Not IsNull(ANumber),Right("00" & Anumber,2), ANumber)
FROM Table1;