Thanks.
Looking over it, I don't see anything wrong with the SQL. When you use
"NT" and get too many results, is this a case of difference in
lettercase; getting "nt" when you only want "NT"? What kind of term
codes end up in your result that shouldn't be there? What data type is
the termcd column?
FWIW, Here's the query cleaned up. Note the changes made to the criteria
for the date range. I don't expect it to fix the original problem, but
it may be helpful in making it readable.
PARAMETERS
[Enter Term Code] TEXT(2),
[Enter Campaign] TEXT(20),
[Enter Start Date] DATE,
[Enter End Date] DATE
;
SELECT c.number,
c.termcd,
c.calldate,
c.campaign
FROM dbo_calltrack c
WHERE c.termcd = [Enter Term Code]
AND c.campaign = [Enter Campaign]
AND c.calldate BETWEEN [Enter Start Date]
AND [Enter End Date]
;
Note: I guessed on data types & length for the Term Code & Campaign. Do
adjust if it's not correct. While you aren't required to declare
parameters, I do feel that it's best to do so mainly for documentation
and to provide a strong-typed variable.
Sun said:
SELECT dbo_calltrak.number, dbo_calltrak.termcd, dbo_calltrak.calldate,
dbo_calltrak.campaign
FROM dbo_calltrak
WHERE (((dbo_calltrak.termcd)=[Enter Term Code]) AND
((dbo_calltrak.calldate)>=CDate([Enter Start Date: ]) And
(dbo_calltrak.calldate)<DateAdd("d",1,CDate([Enter End Date: (mm/dd/yyyy)])))
AND ((dbo_calltrak.campaign)=[Enter Campaign]));
:
Yes, that's already cleared up. But what I was asking is the SQL for the
MSAccess query.
In Access, if you open the query that is causing the problem in design
view, you can switch over to SQL view by going Tools -> SQL View, then
copy and paste the SQL for the query here so we can provide feedback on
what might be causing the problem.
Did that clarify?
Sun Communications wrote:
Should not have used SQL. I have an Access database linked to a MS SQL 2000
database. So when I run my MSAccess query it is pulling in the extra codes
that I am not looking for.
:
As I asked before, what's the complete SQL of the problematic query?
Sun Communications wrote:
I am using MS SQL 2000.
:
When you say "my SQL database", do you mean MySQL database or your SQL
Server database? (I only ask because several people incorrectly use the
phrase 'SQL database' to refer to Microsoft SQL Server causing some
confusion.)
What is the complete SQL of the query you're using?
Sun Communications wrote:
I have a query for a field in my SQL database and use this statement =[Enter
Term Code]. It prompts for the code that I would like the report for example
"NT", but when it returns the query there are other term codes included. How
do I exclude the others.