在直接和通过VBA excel运行相同的存储Access SQL查询时获得不同的结果

时间:2012-12-27 07:39:11

标签: sql excel excel-vba ms-access-2007 access-vba vba

以下存储的访问查询在通过VBA excel运行时为POEventCode提供“ NA ”,并且在从access直接运行时给出正确的结果。为什么这是异常?

SELECT D.[Event Code] & D.[Week Code] AS POEventCode, *  
INTO A
FROM (SELECT IIf([Advertisement type]='Tabloide','TAB',
    IIf([Advertisement type]='Flyer','FLY','NA')) AS [Event Code], 
    IIf(([Start Date]>[SD] And [Start Date]<[ED]), 
        [Month] & Right([WM_WK],2),'NA')  
        AS [Week Code], *  
    FROM [Feature A-Traits] AS C, [Event Code] AS B) 
AS D
WHERE (D.[Week Code]) Not Like '*NA*'  
    And (D.[Event Code]) Not Like '*NA*';

1 个答案:

答案 0 :(得分:3)

如果您使用ADO通过VBA Excel运行查询,则您的通配符必须为%not *,因此: - Not Like '%NA%'