Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #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))

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




Any help would be greatly appreciated.

Reply With Quote
  #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

Can you change "avg" to "sum?"

Reply With Quote
  #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

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?

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 12:13 PM.

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