Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

RecordCount for Queries Off - Please help.

Guest
Sep 12, 2008 Sep 12, 2008
Ok I have 8 queries the one below loops through the MYSQL database to get the days of the week and then gets the results where they = 1 - 7 and outputs the results using recordcount.

<cfloop index="i" from="1" to="7">
<cfquery name="dailycount#i#" datasource="123">
SELECT ct_id, ct_time, ct_email
FROM contacts
WHERE DayOfWeek(Right(ct_time, 10)) = #i#
GROUP By ct_email
</cfquery>
</cfloop>

Using that query I get the following numbers 24+26+22+38+27 = 137. Now when I do a similar query here.

<cfquery name="DuringBusinessHours" datasource="123">
SELECT ct_id, ct_time, ct_email
FROM contacts
WHERE DayOfWeek(Right(ct_time, 10)) Between 2 AND 6
GROUP By ct_email
</cfquery>

My number is 134 which is off by 3 points. Anyone have any thoughts on this?
654
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 12, 2008 Sep 12, 2008
PopcornCoder wrote:
> <cfloop index="i" from="1" to="7">
...
> </cfloop>
...
> WHERE DayOfWeek(Right(ct_time, 10)) Between 2 AND 6
..

> My number is 134 which is off by 3 points. Anyone have any thoughts on this?

My first guess would be that there are three records that on Sundays or
Saturdays (1 or 7).

Your first query uses the values 1 through 7, your second only 2 through 6.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 12, 2008 Sep 12, 2008
Sorry I forgot to mention. I have already taken out the saturday and sunday numbers.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Sep 12, 2008 Sep 12, 2008
PopcornCoder wrote:
> My number is 134 which is off by 3 points. Anyone have any thoughts on this?

I would first dump the results of all queries and compare them to determine where the difference lies.

> DayOfWeek(Right(ct_time, 10))

What is the purpose of using Right()?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 12, 2008 Sep 12, 2008
DayOfWeek(Right(ct_time, 10)) gets the date part of the timestamp, the way I have it is hh:mm YYYY/DD/MM.

I do dump the numbers to see I have a table on my page that shows the numbers like this

Sun: 4
Mon: 24
Tue: 26
Wed: 22
Thu: 38
Fri: 27
Sat: 8

Total: 149
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Sep 12, 2008 Sep 12, 2008
What is the data type of the "ct_time" column?

PopcornCoder wrote:
> I do dump the numbers

No, dump the actual query objects:

<cfdump var="#DuringBusinessHours#">
... etc...
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 12, 2008 Sep 12, 2008
Varchar and what does the cfdump do?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 12, 2008 Sep 12, 2008
How can I compare the 2 cfdumps to eachother to find the missing ones?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Sep 12, 2008 Sep 12, 2008
> Varchar and what does the cfdump do?

Generally, dates and time values should be stored in datetime columns, not varchar.

> what does the cfdump do

It is a useful debugging tool. In this case it will display the actual results of the query. Not just the totals.
http://livedocs.adobe.com/coldfusion/7/htmldocs/00000239.htm

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 12, 2008 Sep 12, 2008
DId that and no dice on anything different there
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Sep 12, 2008 Sep 12, 2008
> DId that and no dice on anything different there

Since I cannot see the results, I do not have much else to suggest.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 12, 2008 Sep 12, 2008
How can I compare the 2 cfdumps to eachother to find the missing ones
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 12, 2008 Sep 12, 2008
> How can I compare the 2 cfdumps to eachother to find the missing ones

*Look at them*.

--
Adam
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Sep 12, 2008 Sep 12, 2008
> How can I compare the 2 cfdumps to eachother to find the missing ones

You would not. A cfdump is a visual construct. What you would need to compare is the queries. Either visually or through sql. In sql you typically use an OUTER JOIN to find records that exist in one table that do not exist in another. It does not have to use literal tables. It could be two derived tables, which is just a a select nested in parenthesis. The results of the select can be treated like a virtual table.

SELECT d.Title, d.NumORecords
FROM (
SELECT Title, COUNT(*) AS NumOfRecords
FROM SomeTable
GROUP BY Title
) as d

If you are not familiar with joins, I suggest you review the online documentation. For MySQL its:
http://dev.mysql.com/doc/refman/5.0/en/join.html

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 13, 2008 Sep 13, 2008
i think your problem is that you store date values as text instead of
date objects and the 'date' you pass to DAYOFWEEK function is not in
correct format. mysql expects a date in YYYY-MM-DD or YYYY/MM/DD format
while you are passing a date string as YYYY/DD/MM. thus some of the
'dates' you pass to the function will validate as dates but others will
not - in any case even the ones that do validate will be NOT the dates
you espect (i.e. if you pass '2008/01/10' expecting it to return day of
week for October 1, 2008, it will actually return day of week for
January 10, 2008 because of the wrong date format you are passing to the
function)

run this simple test:

<cfquery name="q1" datasource="you_dsn_here">
SELECT DAYOFWEEK(RIGHT('11:00 2008/14/09', 10)) AS date1,
DAYOFWEEK(RIGHT('11:00 2008/09/14', 10)) AS date2
FROM some_table_name_here
</cfquery>
<cfoutput>DATE1: #q1.date1# | DATE2: #q1.date2#</cfoutput>

you will see that the above returns NULL (empty string) for DATE1
(because the date passed to function - day 9 of month 14 of year 2008 -
in is not valid), and 1 for DATE2.

lesson learned: a) store your dates as dates to avoid this; b) read you
db docs to see what a function expects as arguments.

hth


Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 14, 2008 Sep 14, 2008
LATEST
Check for duplicates, for example, by running

SELECT DayOfWeek(Right(ct_time, 10)) as weekDay
FROM contacts
WHERE DayOfWeek(Right(ct_time, 10)) Between 2 AND 6

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources