[Microsoft] [ODBC Microsoft Access驱动程序]条件表达式中的数据类型不匹配

时间:2014-08-15 22:19:41

标签: sql-server ms-access asp-classic access-vba

使用mssql后端的经典asp应用程序,但其中一个工具(收集并显示相关的客户和部门发票)将其数据存储在一个小型Jet数据库中。

为了将两者合并为一个记录集,我们创建了一个Access数据库shell,并在其中链接了表元素以关联MSSQL和Access元素。在Web服务器(IIS8)上下载并安装了最新的MS Access驱动程序,调整了标头以扩充应用程序脚本标头中新shell数据库的连接字符串。

经典的asp然后构建查询,我们做一个response.write,将生成的sql复制/粘贴到access和test中,效果很好。

回到Web服务器,它会出现“数据类型不匹配错误”。

我打破了两个子查询来测试来自web服务器配置,并且每个查询分别在web服务器上执行。它们一起在IIS上爆炸,但在粘贴到MS Access SQL窗口时运行正常,没有任何变化。

这是构建查询的经典ASP:

strSQL = "" &_
            "SELECT AR.Invoice, AR.Amount, AR.PostingDate, AR.Total, AR.Document, AR.SummaryId, AR.Description, AR.JobNumber, " &_
            "AR.Reference, AR.JobDescription, AR.InvoiceDate, AR.Contact, Temps.SumOfQuantity, Temps.Customer " &_
            "FROM " &_
                "(SELECT ARSummary.Invoice, ARDetail.Amount, ARDetail.PostingDate, ARSummary.Total, ARDetail.Document, ARSummary.SummaryId, " &_
                "ARDetail.Description, Orders.JobNumber, Orders.Reference, Orders.JobDescription, ARSummary.InvoiceDate, " &_
                "ARCustomers.Contact " &_
                "FROM (((ARSummary LEFT JOIN ARCustomers ON ARSummary.Customer = ARCustomers.Customer) " &_
                "LEFT JOIN ARDetail ON ARSummary.SummaryId = ARDetail.SummaryId) " &_
                "LEFT JOIN ArTerms ON ARCustomers.TermsCode = ArTerms.TermsCode) " &_
                "RIGHT JOIN Orders ON ARSummary.Reference = Orders.Reference " &_
                "WHERE " & strWhereClause & ") " &_
            "AS AR LEFT JOIN " &_
                "(SELECT DISTINCT(HistoryDetail.Invoice), Orders.JobNumber, HistoryDetail.Reference,  HistoryDetail.InvoiceDate, " &_
                "Sum(HistoryDetail.Quantity) AS SumOfQuantity, Customers.Customer " &_
                "FROM Orders RIGHT JOIN ((HistoryDetail LEFT JOIN Applicants ON HistoryDetail.AppId = Applicants.ApplicantID) " &_
                "LEFT JOIN Customers ON HistoryDetail.Customer = Customers.Customer) ON Orders.Reference = HistoryDetail.Reference " &_
                "GROUP BY HistoryDetail.Invoice, Orders.JobNumber, HistoryDetail.Reference, HistoryDetail.InvoiceDate, Customers.Customer " &_
                "HAVING " & strHavingClause & ") " &_
            "AS Temps " &_
            "ON AR.Invoice = Temps.Invoice " &_
            " ORDER BY AR.JobNumber, AR.JobDescription, AR.InvoiceDate, Temps.Customer, AR.Invoice"

...以及由脚本构建和输出的结果查询:

SELECT AR.Invoice, AR.Amount, AR.PostingDate, AR.Total, AR.Document, AR.SummaryId, AR.Description, AR.JobNumber, AR.Reference, AR.JobDescription, AR.InvoiceDate, AR.Contact, Temps.SumOfQuantity, Temps.Customer 
FROM (
    SELECT ARSummary.Invoice, ARDetail.Amount, ARDetail.PostingDate, ARSummary.Total, ARDetail.Document, ARSummary.SummaryId, ARDetail.Description, Orders.JobNumber, Orders.Reference, Orders.JobDescription, ARSummary.InvoiceDate, ARCustomers.Contact FROM 
        (((ARSummary LEFT JOIN ARCustomers ON ARSummary.Customer = ARCustomers.Customer) 
        LEFT JOIN ARDetail ON ARSummary.SummaryId = ARDetail.SummaryId)
        LEFT JOIN ArTerms 
            ON ARCustomers.TermsCode = ArTerms.TermsCode) 
    RIGHT JOIN Orders 
        ON ARSummary.Reference = Orders.Reference 
    WHERE (ARSummary.InvoiceDate BETWEEN #5/17/2014# AND #8/15/2014#) AND ((ARSummary.Customer='PERSON')) 
    )   AS AR LEFT JOIN
(SELECT DISTINCT(HistoryDetail.Invoice), Orders.JobNumber, HistoryDetail.Reference, HistoryDetail.InvoiceDate, Sum(HistoryDetail.Quantity) AS SumOfQuantity, Customers.Customer 
    FROM Orders 
    RIGHT JOIN ((HistoryDetail LEFT JOIN Applicants ON HistoryDetail.AppId = Applicants.ApplicantID) 
    LEFT JOIN Customers 
        ON HistoryDetail.Customer = Customers.Customer) 
        ON Orders.Reference = HistoryDetail.Reference 
    GROUP BY HistoryDetail.Invoice, Orders.JobNumber, HistoryDetail.Reference, HistoryDetail.InvoiceDate, Customers.Customer HAVING ((Customers.Customer='PERSON')) 
    ) AS Temps 
ON AR.Invoice = Temps.Invoice
ORDER BY AR.JobNumber, AR.JobDescription, AR.InvoiceDate, Temps.Customer, AR.Invoice

...我有点茫然,几天来一直在仔细检查日期字段,这似乎是我在研究中发现的最常见的原因,但是交换哈希标签和ansi引号对错误没有影响。

这份报告已经投入生产了大约六年,几个月前我们的软件供应商将他们的软件包更新到MSSQL,并选择将A / R数据分开并放在少数脱节的Access DB中。

作为将所有内容移植到Web(此处:https://www.personnelinc.com/include/system/tools/activity/reports/usage/#)的“管道”的VMS软件在MySQL上本机运行,但没有使用MySQL调用来收集MSSQL / Access数据(它们分开运行MySQL和MSSQL之间没有共享信息。)

@Brad:我实现了更改和建议,并更新了生成的代码/ sql,我仍然得到相同的数据类型不匹配错误,当我将代码直接粘贴到Access时,代码仍然运行(虽然现在快得多)。

0 个答案:

没有答案