1

我有一个表,其中一些字段是 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`
4

1 回答 1

1

你可以使用:

SELECT Format(ANumber,"00") AS Expr1 
INTO [Text;FMT=Fixed;DATABASE=Z:\docs].[exp.txt] 
FROM table1;

schema.ini可以提供帮助。例如,处理 TransferText 错误

或者,这将创建一个两位数:

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;
于 2013-02-15T20:09:50.127 回答