Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 10th, 2006, 12:45 PM
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with SQL query

Hi, I am trying to extract monthly TNA values from Access table. Here's the code. However, this returns the data by dividing each months data by 12. I don't want this. I just need the monthly data. If I remove the "avg" function, my code isn't working (I am getting the error message as Syntax error(missing operator) in query expression))

SELECT DISTINCTROW [MONTHLY_TNA].ICDI_NO,
mid([MONTHLY_TNA].CALDT,1,4) AS [Date By Year],
avg(IIf((mid([MONTHLY_TNA].CALDT,5,2)=01),[MONTHLY_TNA].[MTNA],0)) AS Jan,
avg(IIf((mid([MONTHLY_TNA].CALDT,5,2)=02),[MONTHLY_TNA].[MTNA],0)) AS Feb,
avg(IIf((mid([MONTHLY_TNA].CALDT,5,2)=03),[MONTHLY_TNA].[MTNA],0)) AS Mar,
avg(IIf((mid([MONTHLY_TNA].CALDT,5,2)=04),[MONTHLY_TNA].[MTNA],0)) AS Apr,
avg(IIf((mid([MONTHLY_TNA].CALDT,5,2)=05),[MONTHLY_TNA].[MTNA],0)) AS May,
avg(IIf((mid([MONTHLY_TNA].CALDT,5,2)=06),[MONTHLY_TNA].[MTNA],0)) AS Jun,
avg(IIf((mid([MONTHLY_TNA].CALDT,5,2)=07),[MONTHLY_TNA].[MTNA],0)) AS Jul,
avg(IIf((mid([MONTHLY_TNA].CALDT,5,2)=08),[MONTHLY_TNA].[MTNA],0)) AS Aug,
avg(IIf((mid([MONTHLY_TNA].CALDT,5,2)=09),[MONTHLY_TNA].[MTNA],0)) AS Sep,
avg(IIf((mid([MONTHLY_TNA].CALDT,5,2)=10),[MONTHLY_TNA].[MTNA],0)) AS Oct,
avg(IIf((mid([MONTHLY_TNA].CALDT,5,2)=11),[MONTHLY_TNA].[MTNA],0)) AS Nov,
avg(IIf((mid([MONTHLY_TNA].CALDT,5,2)=12),[MONTHLY_TNA].[MTNA],0)) AS Dec

FROM [MONTHLY_TNA] INNER JOIN [FUND_STYLE] ON ([MONTHLY_TNA].ICDI_NO = [FUND_STYLE].ICDI_NO)

WHERE ((((([FUND_STYLE].SP_OBJ_CD="AGG" Or [FUND_STYLE].SP_OBJ_CD="GRI" Or [FUND_STYLE].SP_OBJ_CD="GRO" Or [FUND_STYLE].SP_OBJ_CD="GMC" Or [FUND_STYLE].SP_OBJ_CD="SCG") AND ([MONTHLY_TNA].CALDT > 19931231) AND ([MONTHLY_TNA].CALDT < 20060101)))=True))

GROUP BY [MONTHLY_TNA].ICDI_NO, mid([MONTHLY_TNA].CALDT,1,4);


Any help would be greatly appreciated.

Thanks,
  #2 (permalink)  
Old August 11th, 2006, 06:31 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Can you change "avg" to "sum?"


mmcdonal
  #3 (permalink)  
Old August 11th, 2006, 09:26 AM
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply. However, if I use sum instead of avg, it is multiplying the actual data by 2 (in some cases) and 3 (in some instances). Any help why is this happening?



Similar Threads
Thread Thread Starter Forum Replies Last Post
sql query i need seearam MySQL 7 November 30th, 2008 03:14 AM
sql query ldp101068 SQL Server 2000 7 December 18th, 2007 04:52 PM
Output Query to txt file from SQL Query everest SQL Server 2005 4 November 22nd, 2007 01:49 AM
SQL Query!! dpkbahuguna Beginning VB 6 5 October 12th, 2007 12:39 AM
SQL query PinkyCat Classic ASP Databases 3 March 11th, 2005 01:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.