Article View: news.software.readers
Article #107558Query filtering
From: Amani
Date: Wed, 14 Aug 2002 14:07
Date: Wed, 14 Aug 2002 14:07
35 lines
1833 bytes
1833 bytes
Hello World ! I have this initial query : SELECT COUNT(*) AS Transactions, DATEPART(year, DDATETIME) AS Year FROM TRANSACTION GROUP BY DATEPART(year, DDATETIME) What I would like to do is to apply a restriction on the DDATETIME column. Let's say I want DDATETIME between 01/01/2000 and 11/03/2002, which is reflected by the HAVING clause below: SELECT COUNT(*) AS Transactions, DATEPART(year, DDATETIME) AS Year FROM TRANSACTIONLOG GROUP BY DATEPART(year, DDATETIME) HAVING (DDATETIME >= '01/01/2000') AND (DDATETIME <= '11/03/2002') The problem is that 1) on one hand this query seems to violate the SQL specification, as DDATETIME is not included in any aggregate function or in the GROUP BY clause. 2) on the other hand, if I added DDATETIME to the GROUP BY clause, I'd loose the benefit of grouping by year as I would get a too detailed resultset. FYI, I am used SQL Sever 2000. Thanks FYH Amani
Technical Details
Message-ID:
<1830aaef.0208140607.de14953@posting.google.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!postnews1.google.com!not-for-mailShow Full Headers
Complete Article Headers
Message-ID: <1830aaef.0208140607.de14953@posting.google.com> Subject: Query filtering Date: Wed, 14 Aug 2002 14:07:01 +0000 From: geramani@yahoo.com (Amani) Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!postnews1.google.com!not-for-mail Newsgroups: news.software.readers Organization: http://groups.google.com/ Lines: 34 NNTP-Posting-Host: 193.121.52.90 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1029334021 5117 127.0.0.1 (14 Aug 2002 14:07:01 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 14 Aug 2002 14:07:01 GMT