Board index » delphi » Summ by month - SQL
Natwar Lat
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
|
Natwar Lat
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Summ by month - SQL
I have a table with two fields
MyDate - tdatetime I would like to display the total of myamount fields on a monthly basis 04/1999 - 1000 I tried the same using SQL but could not do. I am sure there must be Thanking you, -- |
David Gra
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:Summ by month - SQLThe following is copied from the book DB2 Answers! by Richard Levich and should work depending on the version of SQL server that you use- this book is specifically for DB2 and ORACLE : Select t2grp.COLx_Part, sum(T1.COLB) This should actually group by the month within the date column. Now what is string(month(Date_Column)) + '/' + string(year(Date_Column)) instead of just Please note: that the function is pseudo SQL - it is not legal SQL syntax - QuoteNatwar Lath wrote: |
Steve Koters
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:Summ by month - SQLQuoteOn Tue, 4 Jan 2000 12:43:39 +0530, Natwar Lath <l...@kalinga.com> wrote: _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ |
Natwar Lat
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:Summ by month - SQLIn article <387416aa.2078...@news.gte.net>, koter...@NOSPAMgte.net says... Quote> On Tue, 4 Jan 2000 12:43:39 +0530, Natwar Lath <l...@kalinga.com> wrote: -- |
Steve Koters
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:Summ by month - SQLQuoteOn Wed, 5 Jan 2000 09:46:58 +0530, Natwar Lath <l...@kalinga.com> wrote: FoxPro tables) does not support basing a GROUP BY clause on an expression. An example of such an expression would be the extraction of the month and year from a DATE or TIMESTAMP column using the EXTRACT function -- what you would need to do. To get around this limitation, you need to use two queries. The first acts as an SQL view would and only serves to extract the month and year from the date. The second statement uses that intermediary result set and further refines it by aggregating the data and accumulating the aggregations in groups based on data values. For the first query, do no aggregation or grouping. Use the EXTRACT SELECT EXTRACT(YEAR FROM MyDate) AS yy, Save this statement to a text file (with a .SQL filename extension), In the second statement, use a SELECT statement to retrieve data through SELECT yy, mm, CAST(yy AS CHAR(2)) || "/" || CAST(yy AS CHAR(4)) AS If you do not desire the YY and MM columns to appear in visual controls _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ |
Natwar Lat
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:Summ by month - SQLThanks Steve for his detailed reply. The solution work very smoothly. Thanks once again In article <38766e21.3616...@news.gte.net>, koter...@NOSPAMgte.net Quote> On Wed, 5 Jan 2000 09:46:58 +0530, Natwar Lath <l...@kalinga.com> wrote: Natwar Lath Lath Consultants ROURKELA 769012 (INDIA) ~~~ Offshore Software Development ~~~ http://www.kalinga.com/lath |