mr.smith
mr.smith

Reputation: 35

Why does the query below always return zero results?

The following query always returns empty count. Does anyone know why?

SELECT CTM_Export.[Tracking # Label], Count(CTM_Export.[Tracking # Label]) AS LabelCount
FROM CTM_Export
GROUP BY CTM_Export.[Tracking # Label]
HAVING (((CTM_Export.[Tracking # Label])='TPE RV'))

response.write LabelCount

In the CTM_Export table there are three rows with the value "TPE RV". Therefore, LabelCount should not be empty. But for some reason it is always null.

Upvotes: 1

Views: 82

Answers (2)

HansUp
HansUp

Reputation: 97101

Go back to the data source and examine those values. Perhaps this query actually returns no rows:

SELECT ctm.*
FROM CTM_Export AS ctm
WHERE ctm.[Tracking # Label]='TPE RV'

You may find the [Tracking # Label] values include unexpected space or other non-visible characters.


Seeing one of your comments makes me wonder if something else is going on. Using your original GROUP BY query, add this line to your ASP:

Response.Write "LabelCount: " & tlRS.Fields("LabelCount").Value

Upvotes: 1

Constablebrew
Constablebrew

Reputation: 846

Is there an object you are executing the query on? Looks like lots of code is missing here.

You should perform the count on another field, such as the rowID.

I also recommend you also change "HAVING" to "WHERE".

Upvotes: 0

Related Questions