Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 25th, 2003, 05:44 AM
xyfix xyfix is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 249 xyfix User rank is Private First Class (20 - 50 Reputation Level)xyfix User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 8 h 26 m 57 sec
Reputation Power: 6
error sql in vb

I have a access database, one of the tables in that DB is the main table and one of the tables is a imported table with new records that is inserted into the main table. Inserting records gives no problem, but when I want to know is , which records didnot get inserted. This is how i am trying to do this.

docmd.runsql "create table Recordserrortable ( column1,.....)
docmd.runsql "insert into maintable select * from importedtable"

So far al works, table created and records inserted. Recordserrortable is the table where i want the records to be put if they do not get inserted.
In the following code i get an error "Syntax error in FROM clause."

docmd.runsql "select * from importedtable minus select * from maintable and insert into Recordserrortable"

What is wrong with this code.
__________________

Reply With Quote
  #2  
Old November 25th, 2003, 08:59 AM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
XY - I have to ask you. Minus? I've never seen this SQL Syntax before, although strange things are afoot in Access ("strange things are afoot a the Circle K!" I wonder how many people can remember that quote?). If you want to select rows that are not in one table, but are in the second one, then something along the following lines would be better.

"Insert into RecordsErrorTable Select * from importedtable JOIN maintable on importedtable.YourPrimaryField <> maintable.YourPrimaryField"

This syntax assumes that the values in the primary field of your imported table and your main table are the same, as well as their data type. I believe that this should give you the results that you want, although Access is a strange creature. So, if this doesn't work, then let me know and I'll try something else.
__________________
Fisherman

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein

Reply With Quote
  #3  
Old November 25th, 2003, 10:25 AM
hedge hedge is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2002
Posts: 692 hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 23 h 15 m 53 sec
Reputation Power: 19
Minus is Oracle syntax, too bad it wasn't standard SQL

Reply With Quote
  #4  
Old November 25th, 2003, 10:46 AM
xyfix xyfix is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 249 xyfix User rank is Private First Class (20 - 50 Reputation Level)xyfix User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 8 h 26 m 57 sec
Reputation Power: 6
error sql in vb

Fisherman , it doesn't work, i still get the message "syntax error FROM clause"

Reply With Quote
  #5  
Old November 25th, 2003, 10:58 AM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
Try it without using an Explicit JOIN statement... try using a Where clause.. like so...


"Insert into RecordsErrorTable Select * from importedtable, maintable WHERE importedtable.YourPrimaryField <> maintable.YourPrimaryField"

or maybe

"Insert into RecordsErrorTable Select * from importedtable, maintable WHERE NOT importedtable.YourPrimaryField = maintable.YourPrimaryField"

if the = sign on the last one doesn't work right, try the 'LIKE' operator instead. Access SQL is screwy.. I've never liked working in it very much

Reply With Quote
  #6  
Old November 26th, 2003, 04:20 AM
xyfix xyfix is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 249 xyfix User rank is Private First Class (20 - 50 Reputation Level)xyfix User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 8 h 26 m 57 sec
Reputation Power: 6
error sql in vb

Sorry Fisherman, both of the statements didn't work.
But i found the statement that works only i made it with access query wizard. And if i look at the SQL design of it i see

SELECT * FROM imported table LEFT JOIN maintable ON importedtable. primaryfield=maintable.primaryfield WHERE (((maintable.primaryfield) is null));

when i run this sql in vb like this

qry = "SELECT ..........."
docmd.runsql qry

I get an error message
"error 3063 while executing":
"Duplicate output destination 'primaryfield'.

what is wrong

Reply With Quote
  #7  
Old November 26th, 2003, 07:39 AM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
well, I don't know if this would have any bearing, but if you cut and pasted that SQL Statement, then there is a space between maintable and Primary field

Reply With Quote
  #8  
Old November 27th, 2003, 04:43 PM
xyfix xyfix is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 249 xyfix User rank is Private First Class (20 - 50 Reputation Level)xyfix User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 8 h 26 m 57 sec
Reputation Power: 6
error sql in vb

you're right, the script works and it must have been some kind of spacing in the syntax. So thanks anyway Fisherman.

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > error sql in vb


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT