Solved

Failure of INSERT INTO...

Posted on 2002-06-08
3
216 Views
Last Modified: 2012-06-27
I wrote a simple script using the Jet 4.0 Provider to assist in removing duplicates from a standard ASCII file, while keepng the original line number intact ( hence I could not use a DISTINCT clause ). The SQL statements follow:

; import the text file
'SELECT * INTO [line] FROM [input.txt] IN "" [TEXT;DATABASE=c:\temp]'

;add a line counter
'ALTER TABLE line ADD linecount COUNTER'

;create a temp table with a constraint
"CREATE TABLE temp (line TEXT (50),linecount COUNTER );"
'CREATE UNIQUE INDEX temp ON temp (line)'

'INSERT INTO temp (line,linecount) SELECT * FROM line;'

"SELECT line INTO [Text;DATABASE=c:\temp].[output.txt] FROM temp ORDER BY linecount"


I get no errors, but both the output file and temp table are blank.

If I open Access, create a query and type in the INSERT statment above, it work fine, but Access forces you to confirm 2 warning screens saying it cannot apend all records.

I was wondering if this could be part of the problem and perhaps I need to add something to the script to turn the warnings off.

stan
0
Comment
Question by:stanl
[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
3 Comments
 
LVL 54

Expert Comment

by:nico5038
ID: 7064561
Hi stanl,

Why are you using a script?
You can define a linked table in access to your textfile and issue all needed queries on that linked table.

Removing duplicates could be done by a GroupBy query to select the first line of each unique value and followed by a delete of the non-matching.

Nic;o)
0
 
LVL 9

Accepted Solution

by:
ornicar earned 200 total points
ID: 7064991
If you want to turn the messages off, just use:

DoCmd.SetWarnings False

And to turn them on again:

DoCmd.SetWarnings True

The duplicates will not be added with no message. If this is ok for you, that's fine. I feel it would be better to import into an intermediate table allowing duplicates, then run a check-duplicates query to show these records. Very often it's better to check why there are duplicates and what there are. Just a guess.

0
 

Author Comment

by:stanl
ID: 7065160
As it turned out, if I changed my original OLE Object from the Jet OLEDB Provider to Access.Application the script worked fine.  Since the DoCmd is not part of the Provider Object, that got me thinking about making that change ( but there was never a need to even touch the SetWarnings property.

I agree about holding the duplicates, but the text files are created by 'cut-and-paste' which is subject to slight error.



0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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