|
-
Mar 3rd, 2006, 09:09 AM
#1
Thread Starter
Addicted Member
[RESOLVED] SQL Help
I'm trying to write an SQL expression so that I can pull all the data from the TEST table into the MAIN table where the Product number (PROD) of Test is not in the ALTER table. Basically I'm trying to do an INSERT INTO nested query. Here is the code I have so far and it's not working:
VB Code:
INSERT INTO [MAIN] ([PICKSL], [SLOT], [RES],[PROD],[DESC],[PACK],[MANU ID],[HITIX],[PALLET ID],[PALLET QTY],[DFP]) ;
SELECT t.PICKSL, t.SLOT, t.RES, t.PROD, t.DESC, t.PACK, t.[MANU ID], t.HITIX, t.[PALLET ID], t.[PALLET QTY], t.DFP
FROM Test AS t;
WHERE (((Exists (SELECT *
FROM [ALTER] a
WHERE a.PROD = t.PROD
))=False));
Any help would be greatly appreciated.
Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.
-
Mar 3rd, 2006, 09:50 AM
#2
Re: SQL Help
DESC is a resevre word in SQL so you should put it in square brackets as well. And why do you have semi-colos at the end. If it is a one query then there shouldn't be any semi-colons in between.
Try this
Code:
INSERT INTO
[MAIN] ([PICKSL], [SLOT], [RES],[PROD],[DESC],[PACK],
[MANU ID],[HITIX],[PALLET ID],[PALLET QTY],[DFP])
SELECT
t.PICKSL, t.SLOT, t.RES, t.PROD, t.[DESC], t.PACK, t.[MANU ID],
t.HITIX, t.[PALLET ID], t.[PALLET QTY], t.DFP
FROM Test AS t WHERE Not Exists (SELECT * FROM [ALTER] a WHERE a.PROD = t.PROD)
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Mar 3rd, 2006, 09:52 AM
#3
Re: SQL Help
Why are there semi-colons inside the SQL statement? (before the Select and Where)
Your Where clause could be written a bit more cleanly:
Code:
WHERE Not Exists (SELECT *
FROM [ALTER] a
WHERE a.PROD = t.PROD
);
However, whether this format is the correct method for Insert/Select depends on which DBMS you are using.
-
Mar 3rd, 2006, 10:04 AM
#4
Thread Starter
Addicted Member
Re: SQL Help
I am using MS Access, I have made the changes per Shuja Ali and si the geek; however, the data in the TEST table is still not being inserted into the MAIN table. Any other suggestions?
-
Mar 3rd, 2006, 10:13 AM
#5
Re: SQL Help
It all depends on whether this condition is evavluating to true or false.
Code:
WHERE Not Exists (SELECT * FROM [ALTER] a WHERE a.PROD = t.PROD)
Try running just this part and see if it returns any rows
Code:
SELECT
t.PICKSL, t.SLOT, t.RES, t.PROD, t.[DESC], t.PACK, t.[MANU ID],
t.HITIX, t.[PALLET ID], t.[PALLET QTY], t.DFP
FROM Test AS t WHERE Not Exists (SELECT * FROM [ALTER] a WHERE a.PROD = t.PROD)
And are you getting any error message or is it just that data is bnot getting inserted.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Mar 3rd, 2006, 10:20 AM
#6
Thread Starter
Addicted Member
Re: SQL Help
No I'm not getting any error message; it appears to work; however, nothing is being inserted into the MAIN table. I did try just the select statement and if retrieved information. Any other suggestions? Thanks for your time.
-
Mar 3rd, 2006, 10:34 AM
#7
Re: SQL Help
 Originally Posted by manofsteel00
No I'm not getting any error message; it appears to work; however, nothing is being inserted into the MAIN table. I did try just the select statement and if retrieved information. Any other suggestions? Thanks for your time.
Does it show 0 Rows Inserted or any other messagebox?
Can you post what are you using again? Make sure there are no semicolons in the query, just one semi-colon at the end or else it will not insert anything.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Mar 3rd, 2006, 10:49 AM
#8
Thread Starter
Addicted Member
Re: SQL Help
There is no messagebox statement. I am testing it in Access itself as a query. It generates information as a query but never inserts the information into the MAIN table. The code I am using is
INSERT INTO
[MAIN] ([PICKSL], [SLOT], [RES],[PROD],[DESC],[PACK],
[MANU ID],[HITIX],[PALLET ID],[PALLET QTY],[DFP])
SELECT
t.PICKSL, t.SLOT, t.RES, t.PROD, t.[DESC], t.PACK, t.[MANU ID],
t.HITIX, t.[PALLET ID], t.[PALLET QTY], t.DFP
FROM Test AS t WHERE Not Exists (SELECT * FROM [ALTER] a WHERE a.PROD = t.PROD)
-
Mar 3rd, 2006, 10:53 AM
#9
Thread Starter
Addicted Member
Re: SQL Help
Found the problem: I saved the query and it worked fine. My bad. Thanks for all your help though.
Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|