SCENARIO:
SQL Server 2000 Back End.
The customer calls in with a problem and a QUERY is raised. The date
of creation of the record is in the fldDateQuery column.
The user responds to the customer and a RESPONSE is raised. It
contains the ID of the associated QUERY and the date of creation of
the RESPONSE record is in the fldDateResponse column.
The user wishes to know how many queries in the last month were
responded to on the same day.
CANDIDATE SQL:
SELECT COUNT(*) AS NumResponses
FROM tblQuery
INNER JOIN tblResponses ON tblQuery.fldQueryID =
tblResponses.fldQueryID
WHERE (tblQuery.fldDateQuery < CONVERT(DATETIME,'2003-9-8 00:00:00',
102))
AND (tblQuery.fldDateQuery > CONVERT(DATETIME,'2003-8-8 00:00:00',
102))
AND (DATEDIFF(Day, tblQuery.fldDateQuery,
tblResponses.fldDateResponse) <= 1)
PROBLEM:
If a query has more than one response raised on it within a day of the
query being logged, it counts all those responses. In other words,
the SQL counts the number of matching RESPONSES, and not the number of
QUERIES.
TIA
Edward 3 1848
Edward,
Use COUNT(DISTINCT tblResponses.fldQueryID) instead of COUNT(*)
Shervin
"Edward" <te********@hotmail.com> wrote in message
news:25*************************@posting.google.co m... SCENARIO:
SQL Server 2000 Back End.
The customer calls in with a problem and a QUERY is raised. The date of creation of the record is in the fldDateQuery column.
The user responds to the customer and a RESPONSE is raised. It contains the ID of the associated QUERY and the date of creation of the RESPONSE record is in the fldDateResponse column.
The user wishes to know how many queries in the last month were responded to on the same day.
CANDIDATE SQL:
SELECT COUNT(*) AS NumResponses FROM tblQuery INNER JOIN tblResponses ON tblQuery.fldQueryID = tblResponses.fldQueryID WHERE (tblQuery.fldDateQuery < CONVERT(DATETIME,'2003-9-8 00:00:00', 102)) AND (tblQuery.fldDateQuery > CONVERT(DATETIME,'2003-8-8 00:00:00', 102)) AND (DATEDIFF(Day, tblQuery.fldDateQuery, tblResponses.fldDateResponse) <= 1)
PROBLEM:
If a query has more than one response raised on it within a day of the query being logged, it counts all those responses. In other words, the SQL counts the number of matching RESPONSES, and not the number of QUERIES.
TIA
Edward
Hi
I can't check this out, but try counting fldDateResponse formatted to a day
(i.e. use CONVERT).
e.g COUNT( CONVERT(char(8),fldDateResponse,112) )
John
"Edward" <te********@hotmail.com> wrote in message
news:25*************************@posting.google.co m... SCENARIO:
SQL Server 2000 Back End.
The customer calls in with a problem and a QUERY is raised. The date of creation of the record is in the fldDateQuery column.
The user responds to the customer and a RESPONSE is raised. It contains the ID of the associated QUERY and the date of creation of the RESPONSE record is in the fldDateResponse column.
The user wishes to know how many queries in the last month were responded to on the same day.
CANDIDATE SQL:
SELECT COUNT(*) AS NumResponses FROM tblQuery INNER JOIN tblResponses ON tblQuery.fldQueryID = tblResponses.fldQueryID WHERE (tblQuery.fldDateQuery < CONVERT(DATETIME,'2003-9-8 00:00:00', 102)) AND (tblQuery.fldDateQuery > CONVERT(DATETIME,'2003-8-8 00:00:00', 102)) AND (DATEDIFF(Day, tblQuery.fldDateQuery, tblResponses.fldDateResponse) <= 1)
PROBLEM:
If a query has more than one response raised on it within a day of the query being logged, it counts all those responses. In other words, the SQL counts the number of matching RESPONSES, and not the number of QUERIES.
TIA
Edward
"Shervin Shapourian" <Sh**********@hotmail.com> wrote in message news:<vo************@corp.supernews.com>... Edward,
Use COUNT(DISTINCT tblResponses.fldQueryID) instead of COUNT(*)
Shervin
"Edward" <te********@hotmail.com> wrote in message news:25*************************@posting.google.co m... SCENARIO:
SQL Server 2000 Back End.
The customer calls in with a problem and a QUERY is raised. The date of creation of the record is in the fldDateQuery column.
The user responds to the customer and a RESPONSE is raised. It contains the ID of the associated QUERY and the date of creation of the RESPONSE record is in the fldDateResponse column.
The user wishes to know how many queries in the last month were responded to on the same day.
CANDIDATE SQL:
SELECT COUNT(*) AS NumResponses FROM tblQuery INNER JOIN tblResponses ON tblQuery.fldQueryID = tblResponses.fldQueryID WHERE (tblQuery.fldDateQuery < CONVERT(DATETIME,'2003-9-8 00:00:00', 102)) AND (tblQuery.fldDateQuery > CONVERT(DATETIME,'2003-8-8 00:00:00', 102)) AND (DATEDIFF(Day, tblQuery.fldDateQuery, tblResponses.fldDateResponse) <= 1)
PROBLEM:
If a query has more than one response raised on it within a day of the query being logged, it counts all those responses. In other words, the SQL counts the number of matching RESPONSES, and not the number of QUERIES.
TIA
Edward
This one worked! Note, however, that because fldQueryID is a SQL
Server Uniqueidentifier field it had to be cast thus:
SELECT COUNT( DISTINCT (CONVERT(varchar(38),
tblResponses.fldQueryID))) AS NumResponses
Many, many thanks to the other people who took the trouble to respond.
Edward This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Manny |
last post by:
I have a web form "Page1.asp" and it reads data from a database, does some
calculations, and displays the records in pages. Works fine.
I have a button that displays on the page, defined as...
|
by: Edward |
last post by:
SCENARIO:
SQL Server 2000 Back End.
The customer calls in with a problem and a QUERY is raised. The date
of creation of the record is in the fldDateQuery column.
The user responds to the...
|
by: DR |
last post by:
for some reason webbrowser1.Navigate() works but causes thread to terminate,
i want to do a GetElementyByID in the same thread that executes the
navigate.. i am totaly stumped:...
|
by: DR |
last post by:
for some reason webbrowser1.Navigate() works but causes thread to terminate,
i want to do a GetElementyByID in the same thread that executes the
navigate.. i am totaly stumped:...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
| |