R
Rey
Need assistance in correcting a query problem I'm having. Might be too
close to problem...
The saved queries (inbound yesterday, inbound MTD) work when executed
interactively in Access 2007 (XP Pro SP3). However, the same queries
when the SQL is executed via an ADO command object returns 0 records.
The SQL statement has been modified to add # signs to date values.
The command object is passed into the function ByRef as it was
instantiated in an earlier Sub. Thought that would be better than
creating and closing a command and connection obj w/i the various
functions.
I've taken the SQL statement that results and run it in the Access
query window and it returns the same results as the saved queries.
Test data is from last month so I change my system date to 4/28/09.
I have other queries using similar statements that return records but
not the inbound nor outbound queries.
Thanks in advance for your comments/suggestions,
Rey
Below are the queries.
' yesterday
stringSQL = "INSERT INTO ResultHolding ( ContactStatus, Yesterday,
MTD ) "
stringSQL = stringSQL & "SELECT 'Inbound' AS ContactStatus, Count(*)
AS Yesterday, 0 AS MTD "
stringSQL = stringSQL & "FROM CallProductivity AS CP "
stringSQL = stringSQL & "WHERE (CP.CallDateTime >= #" & (Date - 1) &
"# and CP.CallDateTime < #" & Date & "#) "
stringSQL = stringSQL & "AND UCase(CP.Subject) LIKE 'I*' "
stringSQL = stringSQL & "AND (CP.CallerName In (SELECT ME.CallerName
FROM MARIXEmployees ME)) "
stringSQL = stringSQL & "GROUP BY CP.Subject;"
' run it
cmd.CommandText = stringSQL
SleepCheap (1)
cmd.Execute numberRecords
SleepCheap (1)
This is the SQL statement from the immediate window.
INSERT INTO ResultHolding ( ContactStatus, Yesterday, MTD ) SELECT
'Inbound' AS ContactStatus, Count(*) AS Yesterday, 0 AS MTD FROM
CallProductivity AS CP WHERE (CP.CallDateTime >= #4/27/2009# and
CP.CallDateTime < #4/28/2009#) AND UCase(CP.Subject) LIKE 'IN*' AND
(CP.CallerName In (SELECT ME.CallerName FROM MARIXEmployees ME)) GROUP
BY CP.Subject;
Here's the saved query.
INSERT INTO ResultHolding ( ContactStatus, Yesterday, MTD )
SELECT "Inbound" AS ContactStatus, Count(*) AS Yesterday, 0 AS MTD
FROM CallProductivity AS CP
WHERE (cp.CallDateTime >= (Date() - 1) and cp.CallDateTime < Date())
AND
UCase(CP.Subject) LIKE "IN*"
AND
(CP.CallerName In (SELECT ME.CallerName FROM MARIXEmployees ME))
GROUP BY subject;
' MTD - month to date
stringSQL = "INSERT INTO ResultHolding ( ContactStatus, Yesterday,
MTD ) "
stringSQL = stringSQL & "SELECT CP.Subject, 0 AS Yesterday, count(*)
AS MTD "
stringSQL = stringSQL & "FROM CallProductivity AS CP "
stringSQL = stringSQL & "WHERE (CP.CallDateTime >= #" & Month(Date) &
"/1/" & Year(Date) & "# and CP.CallDateTime <= #" & Date & "#) "
stringSQL = stringSQL & "AND UCase(CP.Subject) LIKE 'I*' "
stringSQL = stringSQL & "AND (CP.CallerName In (SELECT ME.CallerName
FROM MARIXEmployees ME)) "
stringSQL = stringSQL & "GROUP BY CP.Subject;"
cmd.CommandText = stringSQL
SleepCheap (1)
cmd.Execute numberRecords
SleepCheap (1)
SQL from the immediate window.
INSERT INTO ResultHolding ( ContactStatus, Yesterday, MTD ) SELECT
CP.Subject, 0 AS Yesterday, count(*) AS MTD FROM CallProductivity AS
CP WHERE (cp.CallDateTime >= #4/1/2009# and cp.CallDateTime <=
#4/28/2009#) AND UCase(CP.Subject) LIKE 'IN*' AND (CP.CallerName In
(SELECT ME.CallerName FROM MARIXEmployees ME)) GROUP BY CP.Subject;
Here's the saved query.
INSERT INTO ResultHolding ( ContactStatus, Yesterday, MTD )
SELECT CP.Subject, 0 AS Yesterday, count(*) AS MTD
FROM CallProductivity AS CP
WHERE "(cp.CallDateTime >= #" & Month(Date() & '/1/' & Year(Date()) &
"#" and cp.CallDateTime <= Date())
AND
UCase(CP.Subject) LIKE "IN*"
AND
(CP.CallerName In (SELECT ME.CallerName FROM MARIXEmployees ME))
GROUP BY CP.Subject;
close to problem...
The saved queries (inbound yesterday, inbound MTD) work when executed
interactively in Access 2007 (XP Pro SP3). However, the same queries
when the SQL is executed via an ADO command object returns 0 records.
The SQL statement has been modified to add # signs to date values.
The command object is passed into the function ByRef as it was
instantiated in an earlier Sub. Thought that would be better than
creating and closing a command and connection obj w/i the various
functions.
I've taken the SQL statement that results and run it in the Access
query window and it returns the same results as the saved queries.
Test data is from last month so I change my system date to 4/28/09.
I have other queries using similar statements that return records but
not the inbound nor outbound queries.
Thanks in advance for your comments/suggestions,
Rey
Below are the queries.
' yesterday
stringSQL = "INSERT INTO ResultHolding ( ContactStatus, Yesterday,
MTD ) "
stringSQL = stringSQL & "SELECT 'Inbound' AS ContactStatus, Count(*)
AS Yesterday, 0 AS MTD "
stringSQL = stringSQL & "FROM CallProductivity AS CP "
stringSQL = stringSQL & "WHERE (CP.CallDateTime >= #" & (Date - 1) &
"# and CP.CallDateTime < #" & Date & "#) "
stringSQL = stringSQL & "AND UCase(CP.Subject) LIKE 'I*' "
stringSQL = stringSQL & "AND (CP.CallerName In (SELECT ME.CallerName
FROM MARIXEmployees ME)) "
stringSQL = stringSQL & "GROUP BY CP.Subject;"
' run it
cmd.CommandText = stringSQL
SleepCheap (1)
cmd.Execute numberRecords
SleepCheap (1)
This is the SQL statement from the immediate window.
INSERT INTO ResultHolding ( ContactStatus, Yesterday, MTD ) SELECT
'Inbound' AS ContactStatus, Count(*) AS Yesterday, 0 AS MTD FROM
CallProductivity AS CP WHERE (CP.CallDateTime >= #4/27/2009# and
CP.CallDateTime < #4/28/2009#) AND UCase(CP.Subject) LIKE 'IN*' AND
(CP.CallerName In (SELECT ME.CallerName FROM MARIXEmployees ME)) GROUP
BY CP.Subject;
Here's the saved query.
INSERT INTO ResultHolding ( ContactStatus, Yesterday, MTD )
SELECT "Inbound" AS ContactStatus, Count(*) AS Yesterday, 0 AS MTD
FROM CallProductivity AS CP
WHERE (cp.CallDateTime >= (Date() - 1) and cp.CallDateTime < Date())
AND
UCase(CP.Subject) LIKE "IN*"
AND
(CP.CallerName In (SELECT ME.CallerName FROM MARIXEmployees ME))
GROUP BY subject;
' MTD - month to date
stringSQL = "INSERT INTO ResultHolding ( ContactStatus, Yesterday,
MTD ) "
stringSQL = stringSQL & "SELECT CP.Subject, 0 AS Yesterday, count(*)
AS MTD "
stringSQL = stringSQL & "FROM CallProductivity AS CP "
stringSQL = stringSQL & "WHERE (CP.CallDateTime >= #" & Month(Date) &
"/1/" & Year(Date) & "# and CP.CallDateTime <= #" & Date & "#) "
stringSQL = stringSQL & "AND UCase(CP.Subject) LIKE 'I*' "
stringSQL = stringSQL & "AND (CP.CallerName In (SELECT ME.CallerName
FROM MARIXEmployees ME)) "
stringSQL = stringSQL & "GROUP BY CP.Subject;"
cmd.CommandText = stringSQL
SleepCheap (1)
cmd.Execute numberRecords
SleepCheap (1)
SQL from the immediate window.
INSERT INTO ResultHolding ( ContactStatus, Yesterday, MTD ) SELECT
CP.Subject, 0 AS Yesterday, count(*) AS MTD FROM CallProductivity AS
CP WHERE (cp.CallDateTime >= #4/1/2009# and cp.CallDateTime <=
#4/28/2009#) AND UCase(CP.Subject) LIKE 'IN*' AND (CP.CallerName In
(SELECT ME.CallerName FROM MARIXEmployees ME)) GROUP BY CP.Subject;
Here's the saved query.
INSERT INTO ResultHolding ( ContactStatus, Yesterday, MTD )
SELECT CP.Subject, 0 AS Yesterday, count(*) AS MTD
FROM CallProductivity AS CP
WHERE "(cp.CallDateTime >= #" & Month(Date() & '/1/' & Year(Date()) &
"#" and cp.CallDateTime <= Date())
AND
UCase(CP.Subject) LIKE "IN*"
AND
(CP.CallerName In (SELECT ME.CallerName FROM MARIXEmployees ME))
GROUP BY CP.Subject;