473,402 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

[ASP] Query with DB Access

Hi everyone.

I have this query ASP and Db Access:

Expand|Select|Wrap|Line Numbers
  1. strSql = "SELECT Last(ID) AS ID, " &_
  2.           "A, " &_
  3.           "B, " &_
  4.           "C, " &_
  5.           "COUNT(D) AS TotD, " &_
  6.           "Last(D) AS D, "&_
  7.           "Last(E) AS E, " &_
  8.           "Last(date) AS date, "&_
  9.           "Last(tot) AS tot, "&_
  10.           "Last(MonthName) AS MonthName, "&_
  11.           "Last(IDMonth) AS IDMonth "&_
  12.           "FROM tbl "&_
  13.                "WHERE " &_         
  14.           "(" &_
  15.           "(" &_
  16.           "(IDMonth = 12) OR " &_
  17.           "(IDMonth = 1) OR " &_
  18.           "(IDMonth = 2) OR " &_
  19.           "(IDMonth = 3) " &_
  20.           ") " &_
  21.           "AND " &_
  22.            "(DATE > #2007/12/01#) " &_
  23.           "AND " &_
  24.           "(tot = 0) " &_
  25.           "OR " &_
  26.           "(EX = 'KO') " &_
  27.           "AND " &_
  28.           "(D NOT IN ('SA')) " &_
  29.           "AND " &_
  30.           "(" &_
  31.           "(E = 'NT') " &_
  32.           ")) " &_          
  33.           "GROUP BY D, A, B, C "&_
  34.            "HAVING " &_
  35.            "((COUNT(D)) = 5) " &_
  36.           "ORDER BY ID asc"

The query no error, but extract from the table access all values in the field "E".

Extraction should value equal to E = 'NT'

Can you help me ?
Apr 22 '08 #1
13 1848
DrBunchman
979 Expert 512MB
Hi mike1961,

The problem is your OR condition. You need to be careful when using an OR to surround the conditions with brackets. For example:
Expand|Select|Wrap|Line Numbers
  1. WHERE A = 1 AND B = 2 AND (C = 3 OR C = 4)
Will return different results to
Expand|Select|Wrap|Line Numbers
  1. WHERE A = 1 AND B = 2 AND C = 3 OR C = 4
Let me know how you get on.

Dr B
Apr 22 '08 #2
Thanks moderator for you reply.

I have this response.write query:

[php]
SELECT Last(ID) AS ID, A, B, C, COUNT(D) AS TotD, Last(E) AS E, Last(F) AS F, Last(date) AS date, Last(tot) AS tot, Last(MonthName) AS MonthName, Last(IDMonth) AS IDMonth FROM tbl WHERE (((IDMonth = 12) OR (IDMonth = 1) OR (Month = 2) OR (IDMonth = 3) ) AND (DATE > #2007/12/01#) AND (tot = 0) AND (EX = 'KO') AND (D NOT IN ('SA')) AND ((E = 'NT') )) GROUP BY D, A, B, C HAVING ((COUNT(D)) = 5) ORDER BY ID asc
[/php]

In th DB Access I have rows whit EX = 'KO' AND E = 'NT' but this query not extract this rows...
Apr 22 '08 #3
DrBunchman
979 Expert 512MB
Have you got Query Analyser or something similar you can run this query in to test it? If so, do that and comment out your conditions one by one until you get the data returned you are expecting. That way you'll see where the problem is.

I would hazard a guess that the problem is the AND (D NOT IN ('SA')) line so start with that.

Let me know how it goes,

Dr B
Apr 22 '08 #4
Nothing, not working... :(

[php]
SELECT Last(ID) AS ID, A, B, COUNT(D) AS TotD, Last(E) AS E, Last(F) AS F, Last(date) AS date, Last(tot) AS tot, Last(EX) AS EX, Last(MonthName) AS MonthName, Last(IDMonth) AS IDMonth FROM tbl WHERE (((IDMonth = 12) OR (IDMonth = 1) OR (Month = 2) OR (IDMonth = 3) ) AND (DATE > #2007/12/01#) AND (tot = 0) AND (EX = 'KO') AND ((E = 'NT') )) GROUP BY D, A, B HAVING ((COUNT(D)) = 4) ORDER BY ID asc
[/php]
Apr 22 '08 #5
DrBunchman
979 Expert 512MB
Comment out all your conditions.....presumably the data you are expecting to see will display now?

Then start putting the conditions back in one by one and see which one is preventing your data from displaying.

Dr B
Apr 22 '08 #6
Comment out all your conditions.....presumably the data you are expecting to see will display now?

Then start putting the conditions back in one by one and see which one is preventing your data from displaying.

Dr B
OK.

I try this query in the DB Access.

Query working, but I would like see the field "EX"; now no see the field "EX".

[php]

SELECT tbl.A, tbl.B, tbl.C, Count(tbl.D) AS TotD
FROM tbl
WHERE (((tbl.IDMonth)=12 Or (tbl.IDMonth)=1 Or (tbl.IDMonth)=2 Or (tbl.IDMonth)=3) AND ((tbl.DATE)>#12/1/2007#) AND ((tbl.TOT)=0) AND ((tbl.E)='NT'))
GROUP BY tbl.A, tbl.B, tbl.C
HAVING (((Count(tbl.D))=4))
ORDER BY tbl.A;

[/php]
Apr 22 '08 #7
Nothing?

Help me please....
Apr 24 '08 #8
DrBunchman
979 Expert 512MB
I'm not sure what you mean......if you want to see the field EX then you need to include it in your SELECT statement e.g. SELECT EX

Or am I missing something here?

Dr B
Apr 25 '08 #9
I'm not sure what you mean......if you want to see the field EX then you need to include it in your SELECT statement e.g. SELECT EX

Or am I missing something here?

Dr B
But if I include in the SELECt statement the field EX, I have:

[php]

SELECT tbl.A, tbl.B, tbl.C, tbl.EX, Count(tbl.D) AS TotD
FROM tbl
WHERE (((tbl.IDMonth)=12 Or (tbl.IDMonth)=1 Or (tbl.IDMonth)=2 Or (tbl.IDMonth)=3) AND ((tbl.DATE)>#12/1/2007#) AND ((tbl.TOT)=0) AND ((tbl.E)='NT'))
GROUP BY tbl.A, tbl.B, tbl.C, tbl.EX
HAVING (((Count(tbl.D))=4))
ORDER BY tbl.A;

[/php]

The result of query is 109 rows and not see the field EX; without field EX the result of query is 126 rows...

which is the right result ?
Apr 25 '08 #10
DrBunchman
979 Expert 512MB
Is EX null in some of your rows?
Apr 29 '08 #11
Is EX null in some of your rows?
Yes, the field EX is always null...
Apr 29 '08 #12
DrBunchman
979 Expert 512MB
It's always null? If it never contains any data then how come you want to SELECT it?
Apr 29 '08 #13
It's always null? If it never contains any data then how come you want to SELECT it?
In the DB access is not NULL... this query write NULL...
Apr 29 '08 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: david liu | last post by:
access 2000 query: here's what i want to do. from an asp page, perform a search on a table in access. i have used sql code in the asp page itself, but i'd rather execute a query in access. i...
2
by: Joel | last post by:
Hello, ASP does not work locally on my main web site when I browse the machine locally at the console itself, but to the outside world all is fine, and ASP executes normally. I have 4 other...
10
by: Dragonhunter | last post by:
Hello, The aspfaq.com seems to really push stored procedures, and I hear the same advice here all the time. So I want to take the advice. Is it possible to create and practically maintain,...
3
by: Mats | last post by:
It's good practice to validate input, not only where it should be coming from, but from anywhere it's possible to change or add input for a "client". If all user input is transfered using "post"...
1
by: Joris Kempen | last post by:
Hi people, I know that the question has come around sometimes: How to open an Access Report using ASP and export it to for example RTF. I'm trying to implement the first method of David...
2
by: Mattyboy | last post by:
Guys I have built a database with saved queries that runs fine in Access but when I call it from the web using ASP, an exception occurs. I have tried multiple ways of testing the databases with...
6
by: InnoCreate | last post by:
Hi everyone. I've recently written a classic asp website which uses an MS Access datasource. I know this is less than an ideal data source as it has limited functionality. I have a search form on...
8
by: Roland Hall | last post by:
In Access you use "*" + + "*", + can be replaced with & Calling a parameterized query in Access requires % be used in place of *, however, all that I have read show dynamic SQL passed to Access: ...
0
by: shamirza | last post by:
· What is view state and use of it? The current property settings of an ASP.NET page and those of any ASP.NET server controls contained within the page. ASP.NET can detect when a form is requested...
2
by: k-man | last post by:
Hi: I have an MS Access query for a table called MyTable. One of my fields in the query is a custom field that looks like "MyField: = MyFunction(ID)" where ID is a field in MyTable. I have...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.