Solved

Access append query receiving ODBC error

Posted on 2013-01-01
3
597 Views
Last Modified: 2013-01-14
I have a series of append queries that suddendly do not work.  I am receiving an ODBC error  ( attached).
I have been struggling with figuring this out. I have tested that tables - run independent queries on the tables... all ok.

It seemes when I take the "cint(mid(charted_date,5,2)) AS MONTH, cint(mid(charted_date,1,4)) AS Year"  out of the SQL it works.   The purpose of this satement is to take the date form of yyyymmdd and just take out the mm and the yy to apend to the table.



INSERT INTO MAK_SAVES
SELECT SITE AS SITE, MONTH AS [MONTH], YEAR AS [YEAR], LOCATION AS LOCATION, 1 AS ERROR, Count(*) AS TOTAL
FROM (SELECT DISTINCT PHM_MAC_ERR_DTL.SITE, PHM_MAC_ERR_DTL.LOCATION, PHM_MAC_ERR_DTL.CHARTED_TIME AS rounded, PHM_MAC_ERR_DTL.PAT_NUM, charted_date, NURSE_ID, cint(mid(charted_date,5,2)) AS MONTH, cint(mid(charted_date,1,4)) AS Year, 1 AS ERROR1, 0 AS ERROR2, 0 AS ERROR3, 0 AS ERROR4
FROM PHM_MAC_ERR_DTL
WHERE SITE in ("1","2","3")
AND  PHM_MAC_ERR_DTL.CHARTED_DATE between MonthRelToday(-1) and MonthRelToday(0)
AND (PHM_MAC_ERR_DTL.ERROR_CODE ="47")
)  AS [%$##@_Alias]
GROUP BY SITE, Month, Year, LOCATION;




Is there an alternate to  " cint(mid(charted_date,5,2)) AS MONTH, cint(mid(charted_date,1,4)) AS Year"


Thanks
EE-ODBC-ERROR.doc
0
Comment
Question by:joylene6
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
keyu earned 500 total points
ID: 38735695
Hi,

see if you wants to retrieve month and year from date no need to go for such a long path....

so insted of

cint(mid(charted_date,5,2)) AS MONTH, cint(mid(charted_date,1,4)) AS Year

use below might helps you...

month(charted_date) as month,year(charted_date) as year


for more references you can also refer below links....

http://www.databasedev.co.uk/retreive_date_query.html
0
 
LVL 1

Author Comment

by:joylene6
ID: 38774936
I did try this and it partially worked. I ened up changing quite alot of things in the code and getting it to work
0
 
LVL 1

Author Closing Comment

by:joylene6
ID: 38774939
Thanks - this did patrtially work and help me find my end solution. Thank you
0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Viewers will learn the different options available in the Backstage view in Excel 2013.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question